Forum Moderators: open
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
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