When Using this Input:
<input type="file" id="file" (change)="useFiles($event)" webkitdirectory directory multiple/>
I get an Object array with all the files inside the folder.
With a fileReader i can read the content and the names of the files:
public readFolder(files: any[]) {
this.fileCache = [];
this.readFile(0, files);
return this.folderReader$.asObservable();
}
private readFile(index, files) {
const reader = new FileReader();
if (index >= files.length) {
this.folderReader$.next(this.fileCache);
return;
}
const file = files[index];
const filename = file.name;
reader.onload = (e: any) => {
this.fileCache.push({
name: filename,
content: e.target.result});
this.readFile(index + 1, files);
};
reader.readAsText(file);
}
}
Now, Is there any possibility to get the name of the Folder using this FileReader? what would be an easy way to get the name of the folder from input?
I am NOT searching on how to get the Path of the files but how to get the name of the folder i am submitting for input.