How to get fullpath of dropped folder from file system

柔情痞子 提交于 2019-11-30 15:51:44

问题


I am trying to implement drag n drop in my application, which need the full path of folder being dropped.

I have done something like this

<html>
<head>
<style>
#dropzone {
    height:200px;
    width: 200px;
    border: 10px dashed #0c0;
    background-color:cyan;
}
</style>                  
</head>
<body>

<div id="dropzone" droppable="true" ondrop ="drop(event)" ondragenter="return false" ondragover="return false">
</div>

<script type="text/javascript">  
function drop(e) {
    e.stopPropagation();
    e.preventDefault();
    var length = e.dataTransfer.items.length;
    for (var i = 0; i < length; i++) {
        var entry = e.dataTransfer.items[i].webkitGetAsEntry();
        if (entry.isDirectory) {
            alert(entry);//here i need to get path of folder being dropped.
        }
    }
}
</script>
</body>
</html

If I alert e.dataTransfer.files[i].name inside for loop then it only show name of folder but not it's path.

Does Javascript allow access to local file system? OR any workaround for this?


回答1:


  • getAsFile does not expose a path-Property. -- not in Chrome -- in IE even dataTransfer.items is unsupported.



回答2:


try

e.dataTransfer.files[0].path

which will give you folder path.



来源:https://stackoverflow.com/questions/35218632/how-to-get-fullpath-of-dropped-folder-from-file-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!