Forum Moderators: open

Message Too Old, No Replies

want a directory file list client-side

         

merijnvw

10:58 pm on Feb 8, 2010 (gmt 0)

10+ Year Member



Hi, I have a webpage that only runs offline and I need to have a list of the files in the directory. PHP is not an option... I understand it's impossible or only possible by doing some weird things in Javascript, I'm not really familiar with AJAX. Can I do it with AJAX? Or with Perl and implement that in the page? What is the best method and how would I do that?

lavazza

11:11 pm on Feb 8, 2010 (gmt 0)

10+ Year Member



If you do NOT have an index file in 'directoryName'(i.e NO index.html or index.php, etc file), then loading
http://localhost/directoryName/
will list the files in 'directoryName'

:)

merijnvw

9:32 am on Feb 9, 2010 (gmt 0)

10+ Year Member



I don't want it listed like that, I want to use it in my javascript and generate stuff with it in my own layout. And indeed I could use that then, by loading it in an invisible iframe and then calling the links-array from the iframe(saw someone do that on another site), but it doesn't work for me, I think that idea was based on an older browser. And moreover if I load a directory in IE offline(and I'm making this for IE people), it opens the directory just like in Windows Explorer, not a list.
And I'm not using 'localhost' as it will run on computers without Apache on, if that was so I could also just use php.

Someone knows another method?

rocknbil

7:48 pm on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



http://localhost/directoryName/ will list the files in 'directoryName'


I'd never heard of this and can't get it to work, what am I missing? :-) Don't you need your comp running as a server?

I don't want it listed like that, I want to use it in my javascript and generate stuff with it in my own layout.


I don't know that this is possible with Javascript alone. Imagine if it were, I could craft a script to snoop the system of any user visiting my site, which would not be good.

Active X and Flash can do this, though.

I think that idea was based on an older browser.


An interesting "feature" (read: bug, alias Peterbilt sized security flaw) of IE 6 was that some methods allowed reading of local files. One trick I used to do was when someone selected a file to upload, JS would write a preview of the image below it. This was a very cool thing, but it was only because I was making use of a security hole. It got fixed in IE 7.

astupidname

10:30 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



Hi, I have a webpage that only runs offline and I need to have a list of the files in the directory. PHP is not an option...
.....
What is the best method and how would I do that?


Well, since it will be run locally only, you could go with JScript -microsoft language (not javascript):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Show Local Folder File List</title>
</head>
<body>
<div>
<script type="text/JScript">
//note this is JScript, not javascript. Thus the 'type="text/JScript"' in the script tags

function ShowFolderFileList(folderspec){
var fso, f, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext()) {
s += fc.item();
s += "<br>";
}
return s;
}

//note folder/file paths should use the local windows style backslash and be escaped '\\' :
var fileList = ShowFolderFileList('C:\\testing\\getfiles');
document.write(fileList);

</script>
</div>
</body>
</html>


Of course, the above is intended to run on IE only.
Note also, that to run it you will need to allow the ActiveXObject to run when IE promts you with it's security warning bar.
For more info, see Microsoft's reference for the FileSystemObject: [msdn.microsoft.com...]
If you look in that reference, you may note that in the reference page(s) they had a set of <strong> tags wrapping f.files, assume that is a html error on the page as it will cause error in the code if you don't remove them and just blindly follow their examples....

merijnvw

10:38 pm on Feb 10, 2010 (gmt 0)

10+ Year Member



Thank you so much astupidname! It works perfect, exactly what I want. Thanks again.

lavazza

11:31 pm on Feb 10, 2010 (gmt 0)

10+ Year Member



http://localhost/directoryName/ will list the files in 'directoryName'

I'd never heard of this and can't get it to work, what am I missing? :-) Don't you need your comp running as a server?

Yes... the localhost approach does require a local server

However,
file:///C:/path/directory/
does not :)