FSO: Using regexps?

Discussion in 'ASP General' started by Ken Fine, Jan 14, 2004.

  1. Ken Fine

    Ken Fine Guest

    I'd like my FSO script to act only on files that fit a pattern, files that
    include "icon" in the name.
    Below, I have FSO code that acts on files that begin with "icon" and have an
    extension of .jpg.

    I'd prefer it if the script would act in instances where "icon" appeared
    anywhere in the filename.

    Any help out there?

    Thanks...


    Dim fso, f, f1, fc, s
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(folder)
    Set fc = f.Files
    For Each f1 in fc
    if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon" Then
    %> <img
    src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br> <%
    end if
    Next
    %>
     
    Ken Fine, Jan 14, 2004
    #1
    1. Advertising

  2. Ken Fine

    Curt_C [MVP] Guest

    Re: Using regexps?

    use Instr() on the retrieved filename to determine if the string is in it

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    "Ken Fine" <> wrote in message
    news:bu2orp$h36$...
    > I'd like my FSO script to act only on files that fit a pattern, files that
    > include "icon" in the name.
    > Below, I have FSO code that acts on files that begin with "icon" and have

    an
    > extension of .jpg.
    >
    > I'd prefer it if the script would act in instances where "icon" appeared
    > anywhere in the filename.
    >
    > Any help out there?
    >
    > Thanks...
    >
    >
    > Dim fso, f, f1, fc, s
    > Set fso = CreateObject("Scripting.FileSystemObject")
    > Set f = fso.GetFolder(folder)
    > Set fc = f.Files
    > For Each f1 in fc
    > if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon" Then
    > %> <img
    > src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br> <%
    > end if
    > Next
    > %>
    >
    >
     
    Curt_C [MVP], Jan 14, 2004
    #2
    1. Advertising

  3. Ken Fine

    Guest Guest

    Re: Using regexps?

    Good advice, thanks Curt. For anyone who needs exact syntax, here's how you
    do it:

    if fso.GetExtensionName(f1) = "jpg" and instr(1,f1,"icon",1) > 0 Then

    I should give this a go with the Regexp method just as a learning thing.

    -KF

    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:...
    > use Instr() on the retrieved filename to determine if the string is in it
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >
    >
    > "Ken Fine" <> wrote in message
    > news:bu2orp$h36$...
    > > I'd like my FSO script to act only on files that fit a pattern, files

    that
    > > include "icon" in the name.
    > > Below, I have FSO code that acts on files that begin with "icon" and

    have
    > an
    > > extension of .jpg.
    > >
    > > I'd prefer it if the script would act in instances where "icon" appeared
    > > anywhere in the filename.
    > >
    > > Any help out there?
    > >
    > > Thanks...
    > >
    > >
    > > Dim fso, f, f1, fc, s
    > > Set fso = CreateObject("Scripting.FileSystemObject")
    > > Set f = fso.GetFolder(folder)
    > > Set fc = f.Files
    > > For Each f1 in fc
    > > if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon"

    Then
    > > %> <img
    > > src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br>

    <%
    > > end if
    > > Next
    > > %>
    > >
    > >

    >
    >
     
    Guest, Jan 14, 2004
    #3
  4. Ken Fine

    Curt_C [MVP] Guest

    Re: Using regexps?

    RegEx is a powerfull thing, I've just never learned it well so I tend to not
    use it :}

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    <> wrote in message
    news:%...
    >
    > Good advice, thanks Curt. For anyone who needs exact syntax, here's how

    you
    > do it:
    >
    > if fso.GetExtensionName(f1) = "jpg" and instr(1,f1,"icon",1) > 0 Then
    >
    > I should give this a go with the Regexp method just as a learning thing.
    >
    > -KF
    >
    > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    > news:...
    > > use Instr() on the retrieved filename to determine if the string is in

    it
    > >
    > > --
    > > Curt Christianson
    > > Owner/Lead Developer, DF-Software
    > > www.Darkfalz.com
    > >
    > >
    > > "Ken Fine" <> wrote in message
    > > news:bu2orp$h36$...
    > > > I'd like my FSO script to act only on files that fit a pattern, files

    > that
    > > > include "icon" in the name.
    > > > Below, I have FSO code that acts on files that begin with "icon" and

    > have
    > > an
    > > > extension of .jpg.
    > > >
    > > > I'd prefer it if the script would act in instances where "icon"

    appeared
    > > > anywhere in the filename.
    > > >
    > > > Any help out there?
    > > >
    > > > Thanks...
    > > >
    > > >
    > > > Dim fso, f, f1, fc, s
    > > > Set fso = CreateObject("Scripting.FileSystemObject")
    > > > Set f = fso.GetFolder(folder)
    > > > Set fc = f.Files
    > > > For Each f1 in fc
    > > > if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon"

    > Then
    > > > %> <img
    > > > src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br>

    > <%
    > > > end if
    > > > Next
    > > > %>
    > > >
    > > >

    > >
    > >

    >
    >
     
    Curt_C [MVP], Jan 14, 2004
    #4
  5. Ken Fine

    swp Guest

    "Ken Fine" <> wrote in message news:<bu2orp$h36$>...
    > I'd like my FSO script to act only on files that fit a pattern, files that
    > include "icon" in the name.
    > Below, I have FSO code that acts on files that begin with "icon" and have an
    > extension of .jpg.
    >
    > I'd prefer it if the script would act in instances where "icon" appeared
    > anywhere in the filename.
    >
    > Any help out there?
    >
    > Thanks...
    >
    >
    > Dim fso, f, f1, fc, s
    > Set fso = CreateObject("Scripting.FileSystemObject")
    > Set f = fso.GetFolder(folder)
    > Set fc = f.Files
    > For Each f1 in fc
    > if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon" Then
    > %> <img
    > src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br> <%
    > end if
    > Next
    > %>


    the only part you need to change is:
    left(f1.name,4) = "icon"

    use something like:
    instr(lcase(f1.name), "icon")
    instead, which returns zero (aka false) if "icon" is not found within
    the lowercase string f1.name.

    syntax and typos go hand in hand, please don't blame me for either

    swp
     
    swp, Jan 15, 2004
    #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. Replies:
    4
    Views:
    577
  2. JohnL

    Data Type Change while using FSO?

    JohnL, Apr 13, 2004, in forum: ASP General
    Replies:
    7
    Views:
    172
    Aaron Bertrand [MVP]
    Apr 13, 2004
  3. Stephen Last

    Problem using FSO with mapped drive...

    Stephen Last, Jun 15, 2004, in forum: ASP General
    Replies:
    1
    Views:
    263
    Aaron [SQL Server MVP]
    Jun 15, 2004
  4. Tomas Eklund

    Creating Mac-codepage file using FSO

    Tomas Eklund, Nov 4, 2005, in forum: ASP General
    Replies:
    0
    Views:
    125
    Tomas Eklund
    Nov 4, 2005
  5. Brendan Byrd/SineSwiper

    Removing Perl comments and strings using regexps

    Brendan Byrd/SineSwiper, Jul 17, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    156
    Brendan Byrd/SineSwiper
    Jul 18, 2003
Loading...

Share This Page