PDA

View Full Version : Modify existing directory tree listing script to exclude certain file types


dravon
05-12-2006, 02:05 AM
I did read the sticky posts on directory listing (http://www.codingforums.com/showthread.php?t=8736) and I also read the post about excluding certain file types (http://www.codingforums.com/showthread.php?t=68639). Neither of these posts is helping me solve my problem. Starting with the BrainJar directory display code, it was heavily modified so that now it displays only the name of the file with URL link but only if that file was updated in the last 7 days.

My code looks like this and as it stands works fine, except for one issue - I don't want it to print every single file which meets the 7-day parameter.


<% ListFolderContents(Server.MapPath("/performance")) %>
<% sub ListFolderContents(path)

dim strDate()
Redim strDate(7)
strDate(0) = Date()
strDate(1) = Date()-1
strDate(2) = Date()-2
strDate(3) = Date()-3
strDate(4) = Date()-4
strDate(5) = Date()-5
strDate(6) = Date()-6
strDate(7) = Date()-7

dim fs, folder, file, item, url, when

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

for each item in folder.SubFolders
ListFolderContents(item.Path)
next

for each item in folder.Files
for intCounter = 0 to 7
If InStr(1, item.DateLastModified, strDate(intCounter), vbTextCompare) <> 0 Then
url = MapURL(item.path)
%>

• <a href="<%= url %>"> <%= item.Name %> </A> <br>
<%
end if
next
next
end sub
%>


(the MapURL is another function in the script which I'm not including here). My question is: How would I modify this script to exclude certain file types? I have tried everything I could think of to implement the


<% sub ListFolderContents(path, exclusionPattern)


suggestion from the above referenced thread, but I never got anywhere - it always threw the error at the very first line of the code,


<% ListFolderContents(Server.MapPath("/performance")) %>


never getting past this one. Attempts to add another parameter to this also failed. :confused:

I even tried creating a new string array and turning my If-Then into an If-And-Then, but this worked only if the string matched the file name exactly, and it included rather than excluded.


for each item in folder.Files
for intCounter = 0 to 7
If InStr(1, item.DateLastModified, strDate(intCounter), vbTextCompare) AND If InStr(1, item.Name, strExclude(intCounter), vbTextCompare) <> 0 Then
url = MapURL(item.path)



In case you can't tell, I'm not exactly a programmer. I can modify code somewhat, but if it's a new situation (like this) I have to rely on what I can find or what I read, and so far this one has me totally stumped. Any suggestions would be greatly appreciated! :D

dravon
05-17-2006, 07:57 PM
Since help was not available, I spent several hours poking at the code and found the solution. Gigured I'd post it here in case someone else had the same question.

Replace the opening line of


<% ListFolderContents(Server.MapPath("filepath")) %>


with this version


<% ListFolderContents Server.MapPath("filepath"), Array(".asp", ".inc", ".js") %>


will allow the script to work with the expanded parameters here


<% sub ListFolderContents(path, exclusionPattern)