javascript 如何获取所选文件夹的完整路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17564299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 08:47:48  来源:igfitidea点击:

How To get the full path of the folder selected

javascripthtmldom

提问by insanity

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

我已经<input type="file" name="files" id="fld1" webkitdirectory >在一个 html 文件中创建了。

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

如何获取在 javascript 中选择的目录的完整路径。请帮忙

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.

我想使用 jquery 滑块显示任何文件夹中存在的所有图像文件。我可以获得该文件夹中存在的文件的名称,但我无法获得该文件夹的完整路径。我怎么才能得到它。

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

我这样做是为了获取文件路径,但它只适用于 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>

回答by Darin Dimitrov

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.

出于明显的安全原因,您不能这样做。浏览器不允许您使用 javascript 访问和探索客户端计算机的文件系统。一些浏览器会简单地返回文件的一些假路径。

回答by ilyes kooli

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

检查文件 API 文档文件部分提供了有关文件对象的详细信息。

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.

文件名;在获取时,这必须以字符串形式返回文件名。不同系统上有许多文件名变化;这只是文件名,没有路径信息。在获取时,如果用户代理无法提供此信息,则它们必须返回空字符串。