html5 / Javascript - 如何获取Selected文件夹名称?

时间:2014-07-13 01:24:07

标签: javascript html5

我正在使用webkitdirectory来选择一个文件夹。我想获取选择上传的文件夹名称。

1 个答案:

答案 0 :(得分:20)

HTML:

<asp:FileUpload ID="FileUpload1" onchange="selectFolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory AllowMultiple="true" runat="server" />

<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>