how to check if file extension is member of filter list?

Discussion in 'ASP General' started by bart plessers, Jul 27, 2003.

  1. Hello,

    I am developping a file browser bu use of internet explorer.

    I am already so far that I get a full list of all the files of a selected
    directory.
    However, I only want to display certain files, i.e. pictures: jpg, gif, png,
    tiff, etc...

    So I want to set up a main variable, containing this "filter"

    Now for every listed file, I want to check if its extension is listed in the
    filter.

    How can I achieve this without having an if-then for every extension?


    tia

    bartp




    --

    ==========================================
    Hyper A.R.T.
    bart plessers
    Paul Van Ostaijenlaan 4
    3001 Heverlee
    BELGIUM
    tel: +32 (16) 23.40.85
    fax: +32 (16) 23.41.06
    ==========================================
    bart plessers, Jul 27, 2003
    #1
    1. Advertising

  2. Yan,

    that was what I was looking for!

    will try it tomorrow. Maybe you can provide me with some sytax? How to build
    the list? Is it just a string with all my extensions, separated by "," or
    should I define some table?

    tia

    bartp

    --

    ==========================================
    Hyper A.R.T.
    bart plessers
    Paul Van Ostaijenlaan 4
    3001 Heverlee
    BELGIUM
    tel: +32 (16) 23.40.85
    fax: +32 (16) 23.41.06
    ==========================================





    "yan Roosens" <> wrote in message
    news:...
    > Hello Bart,
    >
    > bart plessers wrote:
    >
    > > Hello,
    > >
    > > I am developping a file browser bu use of internet explorer.
    > >
    > > I am already so far that I get a full list of all the files of a

    selected
    > > directory.
    > > However, I only want to display certain files, i.e. pictures: jpg, gif,

    png,
    > > tiff, etc...
    > >
    > > So I want to set up a main variable, containing this "filter"
    > >
    > > Now for every listed file, I want to check if its extension is listed in

    the
    > > filter.
    > >
    > > How can I achieve this without having an if-then for every extension?

    >
    > You could build a list of the extensions you want to display, with a

    separator
    > (a comma should do the trick) and use Instr(the list, the file extension)
    >
    > Yan
    >
    >
    >
    >
    bart plessers, Jul 28, 2003
    #2
    1. Advertising

  3. bart plessers

    Tia Guest

    "bart plessers" <> wrote in message
    news:...
    > Hello,
    >
    > I am developping a file browser bu use of internet explorer.
    >
    > I am already so far that I get a full list of all the files of a selected
    > directory.
    > However, I only want to display certain files, i.e. pictures: jpg, gif, png,
    > tiff, etc...
    >
    > So I want to set up a main variable, containing this "filter"
    >
    > Now for every listed file, I want to check if its extension is listed in the
    > filter.
    >
    > How can I achieve this without having an if-then for every extension?
    >



    Hi,
    here is my preferred method:


    '-------------------------------------------

    AllowedExtensions = Array("asp", "csv", "doc", "htm")


    For i = 0 To UBound(FileList)
    If IsFileNameOK(FileList(i)) Then ' your code here
    Next


    Function IsFileNameOK(strFileSpec) 'Boolean
    ' Find the dot
    DotPos = InStrRev(strFileSpec, ".")
    If DotPos > 0 Then
    ' get the extension
    strExtension = LCase(Right(strFileSpec, Len(strFileSpec) - DotPos))
    ' Loop through allowable extensions
    For i = 0 To UBound(AllowedExtensions)
    ' Check for a match
    If strExtension = LCase(AllowedExtensions(i)) Then
    IsFileNameOK = True
    Exit For
    End If
    Next ' i
    End If ' dot found
    End Function
    Tia, Jul 28, 2003
    #3
  4. thanx for code and your time!
    Tomorrow I'll be on holliday, but surely give it a try afterwards!

    bartp

    --

    ==========================================
    Hyper A.R.T.
    bart plessers
    Paul Van Ostaijenlaan 4
    3001 Heverlee
    BELGIUM
    tel: +32 (16) 23.40.85
    fax: +32 (16) 23.41.06
    ==========================================





    "Tia" <> wrote in message
    news:bg1pt1$e0h$...
    >
    > "bart plessers" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I am developping a file browser bu use of internet explorer.
    > >
    > > I am already so far that I get a full list of all the files of a

    selected
    > > directory.
    > > However, I only want to display certain files, i.e. pictures: jpg, gif,

    png,
    > > tiff, etc...
    > >
    > > So I want to set up a main variable, containing this "filter"
    > >
    > > Now for every listed file, I want to check if its extension is listed in

    the
    > > filter.
    > >
    > > How can I achieve this without having an if-then for every extension?
    > >

    >
    >
    > Hi,
    > here is my preferred method:
    >
    >
    > '-------------------------------------------
    >
    > AllowedExtensions = Array("asp", "csv", "doc", "htm")
    >
    >
    > For i = 0 To UBound(FileList)
    > If IsFileNameOK(FileList(i)) Then ' your code here
    > Next
    >
    >
    > Function IsFileNameOK(strFileSpec) 'Boolean
    > ' Find the dot
    > DotPos = InStrRev(strFileSpec, ".")
    > If DotPos > 0 Then
    > ' get the extension
    > strExtension = LCase(Right(strFileSpec, Len(strFileSpec) - DotPos))
    > ' Loop through allowable extensions
    > For i = 0 To UBound(AllowedExtensions)
    > ' Check for a match
    > If strExtension = LCase(AllowedExtensions(i)) Then
    > IsFileNameOK = True
    > Exit For
    > End If
    > Next ' i
    > End If ' dot found
    > End Function
    >
    >
    bart plessers, Jul 28, 2003
    #4
  5. thanx for code and your time!
    Tomorrow I'll be on holliday, but surely give it a try afterwards!

    bartp

    --

    ==========================================
    Hyper A.R.T.
    bart plessers
    Paul Van Ostaijenlaan 4
    3001 Heverlee
    BELGIUM
    tel: +32 (16) 23.40.85
    fax: +32 (16) 23.41.06
    ==========================================





    "Daniel Bush" <> wrote in message
    news:...
    > On Mon, 28 Jul 2003 01:39:31 +0200, "bart plessers"
    > <> wrote:
    >
    > >Yan,
    > >
    > >that was what I was looking for!
    > >
    > >will try it tomorrow. Maybe you can provide me with some sytax? How to

    build
    > >the list? Is it just a string with all my extensions, separated by "," or
    > >should I define some table?
    > >
    > >tia
    > >
    > >bartp

    > here's something I whipped up. You should be able to modify it as
    > necessary.
    >
    > function strDir(strPath)
    > Dim fil,fol,arrExt,FSO,intCtr,strOut
    > Set FSO = server.createobject("Scripting.FileSystemObject")
    > arrExt = Array("gif", "jpg", "tif") ' put your extensions in here
    > Set fol = FSO.GetFolder(strDir)
    > strOut = vbNullString
    > For Each fil In fol.Files
    > For intCtr = LBound(arrExt) To UBound(arrExt)
    > If StrComp(Mid(fil.ShortName, InStrRev(fil.ShortName, ".")
    > + 1), arrExt(intCtr), 1) = 0 Then
    > strOut = strOut & fil.Path & "<br>"
    > End If
    > Next
    > Next
    > set FSO=nothing
    > strDir=strOut
    > end function
    > %>
    >
    > <html>
    > <body>
    > <p><%=strDir("c:\pictures")%></p>
    > </body>
    > </html>
    >
    >
    > the function will return a string with <br> between the files. Of
    > course, you can put whatever you want in there for syntax, like
    > "<tr><td>" to return a HTML table, etc.
    >
    > Dan Bush
    >
    >
    bart plessers, Jul 28, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    3
    Views:
    26,975
    Steve
    Aug 25, 2006
  2. Replies:
    3
    Views:
    846
    Peter_Julian
    Oct 10, 2005
  3. zax75
    Replies:
    1
    Views:
    1,096
  4. llothar
    Replies:
    17
    Views:
    1,257
    Steve Holden
    Apr 7, 2008
  5. Dima67
    Replies:
    9
    Views:
    1,198
    Marvin Landman
    Sep 4, 2009
Loading...

Share This Page