4

I have created <input type="file" name="files" id="fld1" webkitdirectory > in an html file.

i can get the files using

 var imageFiles = document.getElementById("fld1"),
filesLength = imageFiles.files.length;
for (var i = 0; i < filesLength; i++) {
  alert(imageFiles.files[i].name);
}

How can i get the full path of the directory selected in javascript . please help

I want to show all the image files present in any folder using jquery slider. i can get the name of the files present in that folder but i cannot get the full path of the folder. how can i get it.

i have done this to get the file path but it only worked in IE

<script language="JavaScript">
 function GetDirectory() {
  strFile = document.MyForm.MyFile.value;
  intPos = strFile.lastIndexOf("\\");
  strDirectory = strFile.substring(0, intPos);
  alert(strFile + '\n\n' + strDirectory);
  return false;
  }
 </script>
insanity
  • 1,148
  • 6
  • 16
  • 29

2 Answers2

4

For obvious security reasons you cannot do that. Browsers won't allow you to access and explore the file system of the client computers using javascript. Some browsers will simply return some fake path to the file.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

Check File API documentation, the File section gives details about the File object.

Quoting from the doc:

The name of the file; on getting, this must return the name of the file as a string. There are numerous file name variations on different systems; this is merely the name of the file, without path information. On getting, if user agents cannot make this information available, they must return the empty string.

ilyes kooli
  • 11,959
  • 14
  • 50
  • 79