Reputation: 70
Is there a way to, with JavaScript, get a list of files from a target folder?
I need to search a folder for XML-files and, if there are any, save the names of them in an array.
Thank you!
Upvotes: 1
Views: 919
Reputation: 2311
No. JavaScript works only in the client. Without AJAX calls, JavaScript has no way of looking through folders on the server or on the client's computer.
A language like PHP or Ruby has a part in the server that would allow it access to the file system on the server, but not plain JavaScript.
As sofrito notes below, HTML5 now has a File API which can be used to manipulate files. However, the API can't do all the things that I listed above: Javascript still can't look through folders on your computer or another person's with the same ability as a C++, Java, Python or Ruby program.
Upvotes: 2
Reputation: 33
HTML5 finally provides a standard way to interact with local files, via the File API specification.
http://www.html5rocks.com/en/tutorials/file/dndfiles/
Upvotes: 3
Reputation: 6949
No, not really. But you can statically type the array.
var xml = [ "something.xml", "somethingelse.xml", "anotherthing.xml" ];
Upvotes: 1