I would like to define a variable, which will include my filename only without any extension.
The example of my file is linked to the index.html
page and it looks like this:
<script src="js/20231014.js" type="text/javascript"></script>
<script src="js/20211204.js" type="text/javascript"></script>
<script src="js/20230423.js" type="text/javascript"></script>
- about 50 more files like these
so I want in my variable only the "20231014" extracted.
I found some nice solutions here:
How to get the file name from a full path using JavaScript?
from where I tried:
var filename = fullPath.replace(/^.*[\\\/]/, '')
but I got an error, that fullPath is not defined. That has led me to this link,
where I tried:
var fullPath = FileSystemEntry.fullPath;
but unfortunately, the error just changed, that fileSystemEntry is not defined.
My another approach was:
var fileurl = '/js/'.replace(/\.[^.]+$/, '')
where I got nothing
and finally
var fileurl = window.location.pathname;
where I got just index.html
instead
Is there any swift solution for extracting the given filename from the link based in the other directory?