| |
<%
Dim dirname, mypath, fso, folder, filez, FileCount
' dirname = "../mp3s/"
dirname = "/projects"
' mypath = "../mp3s/"
mypath = "/projects"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(server.mappath(dirname))
Set filez = folder.Files
FileCount = folder.Files.Count
' This function takes a filename and returns the appropriate image for
' that file type based on it's extension. If you pass it "dir", it assumes
' that the corresponding item is a directory and shows the folder icon.
'function ShowImageForType(strName)
' Dim strTemp
' ' Set our working String To the one passed in
' strTemp = strName
'
' ' if it's Not a directory, Get the extension and Set it to strTemp
' ' if it is a directory, Then we already have the correct value
' if strTemp <> "dir" Then
' strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
' End if
'
' response.write strTemp
'
' ' Set the part of the image file name that's unique To the Type of file
' ' To it's correct value and Set this to strTemp. (yet another use of it!)
' Select Case strTemp
' Case "mp3"
' strTemp = "MP3"
' Case "mp2"
' strTemp = "MP3"
' Case "wav"
' strTemp = "MP3"
' Case "aiff"
' strTemp = "MP3"
' Case "html"
' strTemp = "htm"
' Case "m3u"
' strTemp = "MP3"
' End Select
' ' All our logic is done... build the IMG Tag For display To the browser
' ' Place it into... where else... strTemp!
' ' My images are all GIFs and all start With "dir_" For my own sanity.
' ' They End With one of the values Set In the Select statement above.
' strTemp = " "
' ' Set return value and Exit function
' ShowImageForType = strTemp
'End function
'That's it for functions on this one!
%>
<%' 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 the contents of the folder
' You could just as easily read this from some sort of input, but I don't
' need you guys and gals roaming around our server so I've hard coded it to
' a directory I set up to illustrate the sample.
' NOTE: As currently implemented, this needs to end with the /
strPath = mypath
' Create our FSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Get a handle on our folder
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
' Show a little description line and the
' title row of our table
%>
There
are <%= FileCount-1 %> commercials currently available.
Left click on the file name to view the commercial.
| Commercial: |
File
Size: |
Date
Created: |
<%
' First I deal with any subdirectories.
' I just display them and when you click you go to them via plain HTTP.
' You might want to loop them back through this file once you've set it
' up to take a path as input.
For Each objItem In objFolder.SubFolders
' Deal With the bad VTI's that keep giving our visitors 404's
if InStr(1, objItem, "_vti", 1) = 0 AND 1=2 Then ' just skip this section
%>
| <%= objItem.Name %> |
<%= objItem.Size/1000000%>
<% 'I used this To display the file size In MB, you can Set it to default %>
|
<%= objItem.DateCreated%>
<% 'date of creation %>
|
<%
End if
Next 'objItem
' Now that I've done the SubFolders, do the files!
For Each objItem In objFolder.Files
%>
<% if objItem.Name <> "default.asp" then %>
| <%= objItem.Name %> |
<%
fsize = cstr(objItem.Size/1000000)
point = instrRev( fsize, ".")+1
if point <= 0 OR point => len(fsize) then point = len(fsize)
fsize = mid( fsize, 1, point )
%>
<%= fsize %> Mb |
<%= objItem.DateCreated %> |
<% end if %>
<%
Next 'objItem
Set objItem = Nothing
Set objFolder = Nothing
' All done! Kill off the object variable
' s.
Set objFSO = Nothing
%>
|