Marcin Kostrzewa
Marcin Kostrzewa

Reputation: 595

How to get the contents of the directory from local PC in javascript

How to get the contents of the directory from local PC in javascript/jQuery? For example from C:\Images

Upvotes: 7

Views: 35051

Answers (8)

Plaute
Plaute

Reputation: 4889

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>

Upvotes: 1

Esailija
Esailija

Reputation: 140210

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/

Upvotes: 26

echo_Me
echo_Me

Reputation: 37233

here you can read local files by html5 and javascript using the file APIS

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Upvotes: 2

4b0
4b0

Reputation: 22323

Javascript/Jquery does not have access to the local file system for security reasons. This is not possible.So try some server side base code.

Upvotes: 1

hereandnow78
hereandnow78

Reputation: 14434

it is not possible to have javascript-access to the local file-system from the browser, and this is good so!

Upvotes: 0

looper
looper

Reputation: 1979

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.

Upvotes: 0

slowe
slowe

Reputation: 336

I don't think this is possible because accessing the local file system is a terrible security risk.

Upvotes: 0

czerasz
czerasz

Reputation: 14250

You could write a script using a technology like php, ruby, java which will list all files and then send this information via ajax to Your browser.

But You can't do this only via javascript because of security restrictions.

Upvotes: 0

Related Questions