I have a question, I don't know if it's possible, I haven't found information either, but I want to know if, for example:
I want to call a file via a path, but I don't know the file name, but the folder name does, and it's the only file that exists in it.
Is there a possibility that it detects it directly and in what way can it be done?
I thank you all.
I need it is to call a pdf file, it's a lot more code, but here as such is where I put the path
pdfjsLib.getDocument('../documents/REGLAMENTO DE H&SI JOMAR INVERSIONES SAS 2019.pdf').then((pdf) => {
myState.pdf = pdf;
render();
});
Option 1:
To obtain the list of files that are inside a directory we can use the function
scandir
If we call the function
scandir
indicating the flagSCANDIR_SORT_DESCENDING
and the directory has exactly one file, then the name of the file will be the first result in the array.Example:
Option 2:
Since we know the file extension is
.pdf
, we can also useglob
Example: