Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    34
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Filtering mappath folder

    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
    remanythm

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Hi jerusking---

    It's just another IF...THEN statement

    Code:
    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!
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by Daemonspyre View Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •