...

View Full Version : Filtering mappath folder



jerusking
06-26-2007, 08:06 AM
Hi guys, any idea about filtering files on the mappath folder? I have sample codes for you to see. I just need to view jpg files, let say i have .pdf and .doc on that folder and i just want jpg to view. Thanks

Dim oFilesys, oFolder, oFile, i
Set oFilesys= CreateObject("Scripting.FileSystemObject") Set oFolder= oFilesys.GetFolder(Server.MapPath("/images/" & id & "/"))

i=0
For Each oFile in oFolder.Files
strHTML = strHTML & "<td width='40' height='30'><img src='http://www.edwardsandtowers.com/images/"& RS("propcode") &"/" & oFile.Name &"' style='width:40px; height:30px;' border='0'></td>"

i=i+1

if i = 7 then
strHTML = strHTML & "</tr><tr>"
end if

next
strHTML = strHTML & "</tr></table>"

Set oFolder=Nothing
Set oFilesys=Nothing

Daemonspyre
06-26-2007, 01:18 PM
Hi jerusking---

It's just another IF...THEN statement



Dim oFilesys, oFolder, oFile, i
Set oFilesys= CreateObject("Scripting.FileSystemObject")
Set oFolder= oFilesys.GetFolder(Server.MapPath("/images/" & id & "/"))

i=0
For Each oFile in oFolder.Files
if (UCase(Right(oFile.Name,3)) = "JPG") OR (UCase(Right(oFile.Name,4)) = "JPEG") then
strHTML = strHTML & "<td width='40' height='30'><img src='http://www.edwardsandtowers.com/images/"& RS("propcode") &"/" & oFile.Name &"' style='width:40px; height:30px;' border='0'></td>"
i=i+1
end if

if i = 7 then
strHTML = strHTML & "</tr><tr>"
end if

next

strHTML = strHTML & "</tr></table>"

Set oFolder=Nothing
Set oFilesys=Nothing


Because we are using quotes, you would use the UCase (UpperCase) function [ "JPG" <> "jpg" ].

I can't remember if the File.ScriptingObject does File.Ext, but you can resolve that by using the Right(oFile.Name,3) [look at the last 3 characters of the file name].

I only used JPGs in this example, but you could also use this for GIFs, PNGs, BMPs, etc. You can also use an array if you wanted more than 2 or 3 entries in the OR statement.

HTH!

Spudhead
06-26-2007, 03:33 PM
I can't remember if the File.ScriptingObject does File.Ext, but you can resolve that by using the Right(oFile.Name,3) [look at the last 3 characters of the file name].

It doesn't, but the File object does have a "Type" property that returns "a string containing the file type description" - not the actual MIME type but close enough :)

http://www.devguru.com/technologies/vbscript/14027.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum