How to get the contents of the directory from local PC in javascript/jQuery?
For example from C:\Images
-
you could use nodejs for this... with vanilla javascript/jquery is not possibleBruno– Bruno2012-11-29 11:12:48 +00:00Commented Nov 29, 2012 at 11:12
-
possible duplicate of Local file access with javascriptPaul Alan Taylor– Paul Alan Taylor2012-11-29 11:13:28 +00:00Commented Nov 29, 2012 at 11:13
-
Do you mean in the browser? Thankfully, that's not possible without plugins, as it would be a privacy breach.Oded– Oded2012-11-29 11:14:00 +00:00Commented Nov 29, 2012 at 11:14
-
It’s not possible using client-side scripting.David Hellsing– David Hellsing2012-11-29 11:14:09 +00:00Commented Nov 29, 2012 at 11:14
8 Answers
This only works in google chrome:
<input type="file" webkitdirectory>
This will prompt the user to select a directory and you can then access the files property of the input to see the contained files.
It is then possible to use the File System API to construct a virtual, sandboxed file system of the user selected files and have programmatic access to this virtual filesystem as if it was a real filesystem accessed by desktop app.
There is no way otherwise because that would be a big security issue
Working demo in google chrome: http://jsfiddle.net/JwgqC/
3 Comments
here you can read local files by html5 and javascript using the file APIS
Comments
Now, some years later, accessing to local files works fine in Chrome AND Firefox (52.8, but update Firefox is easy). It works also with IE 11.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>files</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<script>
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
</script>
</body>
</html>
Comments
Javascript can't access the users drive. That would be a big security issue, wouldn't it? :D
Instead, you need to use an other technology like flash or java-applets.