Forum Moderators: open

Message Too Old, No Replies

Using wildcards

         

camman

3:55 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



Hi all,

Should be an easy one this but I'm no ASP coder.
The code below I swiped off the web and neatly goes through a directory I specify and lists out the filenames and their last modified date. What I want to do is to formulate some kind of if statement so that it would ONLY list files with a certain prefix. I'm pretty sure I need to incorporate some kind of wild card but the obvious ones (*,?,%) don't seem to work. Or maybe it's just me syntax. I'm going with the latter!

<%
Dim objFSO, objFile
Dim sMapPath, objFolder

'Create File System Object to get list of files
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get The path for the web page and its dir, change this setting to view different directories!
sMapPath = server.mapPath("./riskassessments") ' this means the current directory

'Set the object folder to the mapped path
Set objFolder = objFSO.GetFolder(sMapPath)
' Then for each file in the object we loop through and print the file and when it was last modified
For Each objFile in objFolder.Files

' ###################

Response.Write "<tr><td><a href=""riskassessments/"&objFile.Name&""" class=""leftnavigation2"">" ' Print out a link to the file
Response.write objFile.Name &" </a></td><td> "& objFile.DateLastModified ' the file name and its date
Response.write " </td></tr>" ' close the tags

Next ' Loop back

' Clear the objects
Set objFSO = Nothing
Set objFolder = Nothing

%>

I've tried putting

fname = objFile.Name
If fname = "RA-Gen*" then

where I've put the #s (and ending it with end If obviously).
And I know that if I fully qualify the name ie

If fname = "RA-Gen-help-me.doc"

it will pick out that filename. I just can't get it to pick out all the filenames starting with RA-Gen etc.

I hope I've made sense, if not let me know and I'll post more info.

Many thanks in advance,

Camman

mattglet

4:41 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you're going to just be using RA-Gen as your prefix, then try:

if left(fname, 6) = "RA-Gen" then
'--- code here
end if

what this is does is:
parses out the first 6 characters of the filename, and checks what they are. if they are RA-Gen, then your condition is met, and the filename will show. hope this helps.

-Matt

camman

4:50 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



Matt,

Thanks very much for that. It works a treat. However do you happen to know if there is such a thing as a "wildcard" that can be used in this situation.

Thanks very much again,

Camman

garann

10:59 pm on Dec 8, 2003 (gmt 0)

10+ Year Member



Hi camman,

If you need a "wildcard", could you use a Regular Expression, instead of String methods? I'm not sure what that would look like in classic ASP, but in .NET it's something like


Dim r = new Regex("^RA-Gen")
If r.IsMatch(fName) Then...

Hope that helps..
g.

camman

9:58 am on Dec 9, 2003 (gmt 0)

10+ Year Member



Cheers Garann,

Not too au fait with the old .NET business yet but that's worth knowing. Thank you.

Camman

RossWal

7:00 pm on Dec 9, 2003 (gmt 0)

10+ Year Member



The MS Scripting Technologies page on MSDN explains regular expressions for classic vb script. Consider taking an asprin ahead of time ;^)

Ross (who should have taken an asprin first)