How to populate directory of files into a web page

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Was asked to perform some support for a non profit (gratis)

They have a document that I can turn into a web page that has links to other files.

What they have asked for is for the web page to link to another page that lists the files in a given directory. They then want to select one of those fiels in the list for viewing.

I can manually populate the list - what I am looking for is a simple mechanism for the web page (scripts/html code) to populate the list when the web page is opened.

Everything is internal to a single server - no external IPs used.

Thanks
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,577
4,492
75
You know...most Apache servers in their default configuration will list the files in a directory.

Otherwise, for Linux:

ls *.txt | sed -e 's/^.*$/<a href="&">&<\/a>/'

Or for Windows use dir /b, and get Sed for Windows, or do:

dir /b *.txt | perl -pe 's/^(.*)$/<a href="$1">$1<\/a>/'

instead or something.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Let me clarify - they are not using a Web server - just a file server.
I am looking for a code snippet that I can embed into the web page that will provide the list of files.

Can the
dir /b *.txt | perl -pe 's/^(.*)$/<a href="$1">$1<\/a>/'
be placed in the intermediate page html to cause the list of the files that allows each to be clicked on?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,577
4,492
75
Ooohkay...if they're not using a web server, what protocol is serving the files? FTP? SMB (Windows shares) on a LAN?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
They are just copying the files onto the file server. The user has the network drive letter mounted/mapped to the directory
 

ahurtt

Diamond Member
Feb 1, 2001
4,283
0
0
You seem to be saying contradictory things. You say you want to make it a web page which implies that you have something that can serve up files via HTTP but you say you don't have a web server.

"They have a document that I can turn into a web page that has links to other files."

You have thoroughly befuddled me.

EDIT: OK, I thought about it a little more, maybe you can try using file:// as the protocol which would be like this for example if I wanted to link to some image file named Icon.bmp on my C: drive in a folder named Icons I could put:

<a href="file:///C:/Icons/Icons.bmp">link text</a>

You would replace the C with whatever drive letter the network drive was mapped to but it better be the same drive letter for everybody or it won't work for everyone. Anyway, is this what you were getting at? You will have to give each person a copy of your "web" page and they will all need to have the network drive containing the linked documents mapped to the same letter.
 
Last edited:

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
They are just copying the files onto the file server. The user has the network drive letter mounted/mapped to the directory

Yeah, so whatever the transport mechanism is, if the file is just being opened from the client (i.e. I point Firefox at a .html file on a share somewhere), then there is no opportunity to replace a tag in it, or execute any script in it. It's just a static text file being shipped over the wire.

What you could do is have a process running on the server side that reads the directories and updates a set of static files with the contents, but you can't have it happen in response to the request from the browser unless you use a web server of some kind.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Ok - sounds like I need a static html page that has the links embedded into it.
There is no simple way to dynamically have the directory page updated without a decent amount of effort.

I originally took a Word document that had hyperlinks and exported it as a Web (html) page. They did not want to have to use the CTRL key when clicking on a hyperlink
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
Ok - sounds like I need a static html page that has the links embedded into it.
There is no simple way to dynamically have the directory page updated without a decent amount of effort.

Do you or someone have access to running scheduled tasks (assuming it is a windows server)? I can help you with a quick vbs that will create a html file on a schedule.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Another possible option might be Greasemonkey, which is a browser add-on that runs little javascript prorgams on the client side. These programs can modify the local document object model... but I think reading the share to get the file list might still be a problem.
 

IronWing

No Lifer
Jul 20, 2001
72,014
32,264
136
Do they want a description of each file or just the links?

If just the links, then you could have a link to the folder. In IE and FireFox, this will show the file list in the folder.

The trouble with webpages on local file servers is that the permissions are usually locked down to prevent any type of scripting on the pages. I have this problem on a "site" I maintain on the company file server. It functions pretty much like any other website as far as the users are concerned but no scripting allowed. To link to directory contents I use the method above.

Edit: All the users in my office have the shared drive mapped to the same letter. Without this common mapping, it wouldn't work.