5

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

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

try

e.dataTransfer.files[0].path

which will give you folder path.

Vijayant Katyal
  • 642
  • 2
  • 12
  • 22