I have some specific questions that I still haven't found any material on forums that could help me.
I need to get the name of the folder I select to upload. I know that for security reasons I can't get the full path, but I would like to get at least the name of the folder I selected. Example:
<input type="file" id="fileToUpload" webkitdirectory directory/>
When selecting a folder, I want to get its name, I don't care about the name of the files inside it, only the folder name. Another problem would be that I also need to get the name even if the selected folder doesn't get any files.
EDIT:
<input type="file" id="FileUpload" onchange="selectFolder(event)"
webkitdirectory mozdirectory msdirectory odirectory directory
multiple />
<script type="text/javascript">
function selectFolder(e) {
var theFiles = e.target.files;
var relativePath = theFiles[0].webkitRelativePath;
var folder = relativePath.split("/");
console.log(folder[0]);
}
</script>
With this code below I get what I want, which is the name of the selected folder, but if the selected folder doesn't have any content inside it doesn't return anything.
does this solve your question
<body>
Hello world
<script>
function get_name(){
var check = document.getElementById("fileToUpload").value;
const arr = check.split("\\");
console.log(arr);
console.log("Is this your folder : " , arr.at(arr.length -1) );
console.log(check);
}
</script>
<input type="file" id="fileToUpload" onchange="get_name()" webkitdirectory directory />
</body>