How can I do a foreach(File file in Directory) kind of thing in jQuery.
Thank you!
How can I do a foreach(File file in Directory) kind of thing in jQuery.
Thank you!
Javascript does not have access to the local file system for obvious security reasons. This is not possible.
Unless you are trying to loop through files on your server, in which case you wouldn't want to use jQuery anyway but something like ASP.NET or PHP or whatever framework you are using.
It is not possible with javascript/jquery to read contents of a directory for security reasons. Imagine you are trying to read the file system of client machine. You can use FSO (File System Object) but that works only in IE. You can use server-side languages such as PHP, ASP.Net for accessing the file system.
If you meant a loop with each
, consider the each
method of though. Example:
$('selector').each(function(){
// your code.....
});
$('selector').each(function(idx, elm){
//some code
});
Will allow you to iterate over a list, applying the same function to each. However, accessing the filesystem is not possible.
If the files are on the client you can't access them for security reasons.
If the files are on the server and you want process the list sever-side you wouldn't use JQuery as it's for client-side scripting.
If the files are on the server and you want to process the list client-side, you could generate the list in the server code and send it down as xml, json, etc.
If the files are on somebody else's server your only options is to recursivly follow links on their site, which is not really something you'd want to be doing with Javascript from a client's browser.