Directory Index
The code in this example was taken from an article on www.asp101.com
The goal is, given a directory listing from the WinXP cmd.exe command line interpreter:
C:\DW_local\roitt\SUB\Chap01>dir Volume in drive C has no label. Volume Serial Number is D01F-9190 Directory of C:\DW_local\roitt\SUB\Chap01 23/02/2007 17:11 <DIR> . 23/02/2007 17:11 <DIR> .. 22/02/2007 13:39 30,820 f01-01.jpg 22/02/2007 13:39 15,462 f01-02.jpg 22/02/2007 13:39 30,916 f01-05.jpg 22/02/2007 13:39 41,496 f01-06.jpg 22/02/2007 13:39 50,646 f01-09.jpg 22/02/2007 13:39 15,656 f01-10.jpg 22/02/2007 13:39 37,924 f01-11.jpg 22/02/2007 13:39 43,859 f01-12.jpg 22/02/2007 13:39 24,545 f01-13a.jpg 22/02/2007 13:39 65,950 f01-15.jpg 22/02/2007 13:39 49,362 f01-16.jpg 22/02/2007 13:39 38,017 f01-17.jpg 22/02/2007 13:39 15,966 f01-18.jpg 22/02/2007 13:39 24,683 f01-19.jpg 22/02/2007 13:39 37,791 M01-1-2.jpg 14/03/2007 11:00 <DIR> print 15 File(s) 523,093 bytes 3 Dir(s) 10,725,838,848 bytes free
or the equivalent in Bash
bash-2.02$ ls -o total 294 -r--r--r-- 1 42556 37791 Feb 22 12:39 M01-1-2.jpg -rw-r--r-- 1 42556 59904 Feb 22 10:47 Thumbs.db -r--r--r-- 1 42556 30820 Feb 22 12:39 f01-01.jpg -r--r--r-- 1 42556 15462 Feb 22 12:39 f01-02.jpg -r--r--r-- 1 42556 30916 Feb 22 12:39 f01-05.jpg -r--r--r-- 1 42556 41496 Feb 22 12:39 f01-06.jpg -r--r--r-- 1 42556 50646 Feb 22 12:39 f01-09.jpg -r--r--r-- 1 42556 15656 Feb 22 12:39 f01-10.jpg -r--r--r-- 1 42556 37924 Feb 22 12:39 f01-11.jpg -r--r--r-- 1 42556 43859 Feb 22 12:39 f01-12.jpg -r--r--r-- 1 42556 24545 Feb 22 12:39 f01-13a.jpg -r--r--r-- 1 42556 65950 Feb 22 12:39 f01-15.jpg -r--r--r-- 1 42556 49362 Feb 22 12:39 f01-16.jpg -r--r--r-- 1 42556 38017 Feb 22 12:39 f01-17.jpg -r--r--r-- 1 42556 15966 Feb 22 12:39 f01-18.jpg -r--r--r-- 1 42556 24683 Feb 22 12:39 f01-19.jpg drwxr-xr-x 2 42556 0 Mar 14 11:00 print
we can create a table with clickable links to the appropriate images, along with information about the size of the individual files.
![]() |
(30k) |
![]() |
(15k) |
![]() |
(30k) |
![]() |
(41k) |
![]() |
(49k) |
![]() |
(15k) |
![]() |
(37k) |
![]() |
(43k) |
![]() |
(24k) |
![]() |
(64k) |
![]() |
(48k) |
![]() |
(37k) |
![]() |
(16k) |
![]() |
(24k) |
![]() |
(37k) |
<%' Now to the Runtime code: Dim strPath 'Path of directory to show Dim objFSO 'FileSystemObject variable Dim objFolder 'Folder variable Dim objItem 'Variable used to loop through folder contents Dim chapter ' Pick path of directory to show ' NOTE: As currently implemented, this needs to end with the / strPath = "/SUB/Chap01/" ' Create our FSO Set objFSO = Server.CreateObject("Scripting.FileSystemObject") ' Get a handle on our folder Set objFolder = objFSO.GetFolder(Server.MapPath(strPath)) %> <table width="53%"> <% Dim fileName Dim lengthFileName Dim figureNumber For Each objItem In objFolder.Files fileName = objItem.Name chapter = "1" lengthFileName = Len(fileName) figureNumber = Mid(fileName,5,lengthFileName-8) If Left(fileName,1) = "M" Then chapter = "M1" figureNumber = Replace(figureNumber,"-",".") End If %> <tr> <td width="41%"> <img src="/graphics/right.gif" alt="" width="10" height="10" /> <a href="/scripts/roitt/figure.asp?chap=01 &fig=<%= fileName %>"> Figure <%= chapter %>.<%= figureNumber %> </a> </td> <td width="59%"> (<%= Round(objItem.Size / 1024, 0) %>k) </td> </tr> <% Next 'objItem ' All done! Kill off our object variables. Set objItem = Nothing Set objFolder = Nothing Set objFSO = Nothing %> </table>
See the code in action