Alexander
Alexander

Reputation: 70

Search a folder for XML files with Javascript

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

Answers (3)

Polyov
Polyov

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

sofrito
sofrito

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

McKayla
McKayla

Reputation: 6949

No, not really. But you can statically type the array.

var xml = [ "something.xml", "somethingelse.xml", "anotherthing.xml" ];

Upvotes: 1

Related Questions