Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listing image folder

Status
Not open for further replies.

anneoctaaf

Programmer
Dec 15, 2003
104
0
0
NL
I need some help with getting all the picturenames - which are in an imagefolder on the webserver - into a dropdownlistbox.

Thanx!
 
try this...
Code:
<SELECT name="myImages">
<%
strImageFolder = "C:\Temp\myImages"
Set objFSO = Server.CreateObject("Scripting.FileSystemObjext")
Set objFolder = objFSO.GetFolder(strImageFolder)

For Each strFile in objFolder.Files
  If InStr(strFile.Name,".jpg") OR InStr(strFile.Name,".gif) Then
    Response.Write "<OPTION>" & strFile.Name & "</OPTION>" & vbcrlf
  End If
Next

Set objFolder = Nothing
Set objFSO = Nothing
%>
</SELECT>

Tony
________________________________________________________________________________
 
I have a slight preference for:
Code:
If Right(strFile.Name, 4) = ".jpg" OR Right(strFile.Name, 4) =".gif" Then
espcially if the files are to be displayed, so that things like MyPicture.gif.zip aren't listed, and espcially so that MyTrojan.jpg.scr simply aren't displayed.
 
for giggles ... maybe this would help

Code:
Function IsImage(Value)
on error resume next
TempArr = Split(lcase(Value),".")
FileExt = TempArr(Ubound(TempArr))
    Select Case FileExt
' dont let this next line wrap
      Case "bmp","dip","rle","emf","iff","lbm","ilbm","jpg","jpe","jpeg","jif","jiff","kdc","pcd","pcx","dcx","pic","pix","png","psd","tga","tif","tiff","wmf"
            IsImage = True
        Case Else
            IsImage = False
    End Select
End Function

then is used like :

If IsImage(strFile.Name) Then
blah blah
End If

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
sorry for the width of the function and stretching out the page, also wanted to mention, reason for the use of split, is to ensure you're getting the last set of text, the file extention, instead of right(value,4) which is a pain because you have to make handling for grabbing the period on 3 letter extentions or handling for missing the period on 4 letter extentions. granted you could:
right(value,Len(value)-InstrRev(value,".")) *GAH!*
Or
Mid(Value,InstrRev(Value,"."))

i try to avoid doing excess string manipulations if i can help it.

another nice part about this is, say there is no file extention it's like a text file or something. if there's no extention the filename is processed instead of the extention in the array method, versus the instrrev methods, or right(value,4) methods (what if the file name is only 2 chars long?) the issue with this "fall back" is IF per chance the non-extention filename is named the same as one of the file extentions.. well it'll be a broken image :)

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top