Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5/Javascript - How to get the Selected folder name?

I am using webkitdirectory to select a folder. I want to get the folder name which is selected for uploading.

like image 245
Noobish Avatar asked Jul 13 '14 01:07

Noobish


1 Answers

html:

<input type="file" id="FileUpload" onchange="selectFolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory multiple />

javascript:

<script type="text/javascript">
function selectFolder(e) {
    var theFiles = e.target.files;
    var relativePath = theFiles[0].webkitRelativePath;
    var folder = relativePath.split("/");
    alert(folder[0]);
}
</script>
like image 103
Noobish Avatar answered Sep 30 '22 13:09

Noobish