Get a collection of files whose names match a regular expression?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chrisso

    Get a collection of files whose names match a regular expression?

    Hi All

    Is it possible with the Microsoft Scripting Runtime library to get a
    collection of all the files in a folder that match a regular
    expression?

    That is, can I make a call through the FileSystemObjec t or a Folder
    object to get just the files that start with the letter 'A' for
    example?

    The only API I can see is Folder.Files which gives *all* the files
    then I would have to sort through and do the pattern matching myself
    which seems like it will be very slow. Any ideas?

    Thanks in advance,
    Chrisso
  • rowe_newsgroups

    #2
    Re: Get a collection of files whose names match a regular expression?

    On Jul 24, 7:05 am, Chrisso <chris75sut...@ gmail.comwrote:
    Hi All
    >
    Is it possible with the Microsoft Scripting Runtime library to get a
    collection of all the files in a folder that match a regular
    expression?
    >
    That is,  can I make a call through the FileSystemObjec t or a Folder
    object to get just the files that start with the letter 'A' for
    example?
    >
    The only API I can see is Folder.Files which gives *all* the files
    then I would have to sort through and do the pattern matching myself
    which seems like it will be very slow. Any ideas?
    >
    Thanks in advance,
    Chrisso
    You can use System.IO.Direc tory.GetFiles to do a much better search
    (with wildcards), however if you wanted to do a Regex search you'd
    have to loop through the files and do a Regex.IsMatch on each file,
    which would be very, very slow. Your other option, which wouldn't
    truly be Regex, would be to create a LINQ query that represented the
    Regex pattern and use it. LINQ should be much faster than using
    Regex.IsMatch.

    Thanks,

    Seth Rowe [MVP]

    Comment

    • Chrisso

      #3
      Re: Get a collection of files whose names match a regular expression?

      Thanks Seth

      I will try out System.IO.Direc tory.GetFiles as wildcard matching is
      fine.

      I am actually wrting my VB code in Excel VBA - do I need to include a
      reference to access this functionality?

      Chrsso

      Comment

      • Patrice

        #4
        Re: Get a collection of files whose names match a regular expression?

        See the Dir function then. It doesn't use regular expression but support the
        * and ? wildcards. Is this enough ?

        An Excel programming group would be better....

        --
        Patrice

        "Chrisso" <chris75sutton@ gmail.coma écrit dans le message de groupe de
        discussion :
        275d3e7e-6792-4d61-9a84-d90c73e6579f...l egroups.com...
        Thanks Seth
        >
        I will try out System.IO.Direc tory.GetFiles as wildcard matching is
        fine.
        >
        I am actually wrting my VB code in Excel VBA - do I need to include a
        reference to access this functionality?
        >
        Chrsso
        >

        Comment

        • rowe_newsgroups

          #5
          Re: Get a collection of files whose names match a regular expression?

          On Jul 24, 7:25 am, Chrisso <chris75sut...@ gmail.comwrote:
          Thanks Seth
          >
          I will try out System.IO.Direc tory.GetFiles as wildcard matching is
          fine.
          >
          I am actually wrting my VB code in Excel VBA - do I need to include a
          reference to access this functionality?
          >
          Chrsso
          Wow, I completely missed that you weren't using .NET. Now that I see
          you aren't, I have to send you to the excel programming group since we
          can't be of help to you here (Excel VBA is in no way VB.NET)



          Thanks,

          Seth Rowe [MVP]

          Comment

          • Chrisso

            #6
            Re: Get a collection of files whose names match a regular expression?

            Thankyou. I will give it a whirl.

            I posted here as I thought the topic was independent of Excel. MS is
            weird.

            Chrisso

            Comment

            • rowe_newsgroups

              #7
              Re: Get a collection of files whose names match a regular expression?

              On Jul 24, 7:49 am, Chrisso <chris75sut...@ gmail.comwrote:
              Thankyou. I will give it a whirl.
              >
              I posted here as I thought the topic was independent of Excel. MS is
              weird.
              >
              Chrisso
              The topic is independent of Excel, but it's not from VBA. Let me
              rephrase my earlier statement:

              VBA is in no way Visual Basic .NET

              Thanks,

              Seth Rowe [MVP]

              Comment

              • =?Utf-8?B?UmFhdDE5Nzk=?=

                #8
                RE: Get a collection of files whose names match a regular expression?

                I would ask VBA questions in the vb6 group vba is 99.9% vb6

                "Chrisso" wrote:
                Hi All
                >
                Is it possible with the Microsoft Scripting Runtime library to get a
                collection of all the files in a folder that match a regular
                expression?
                >
                That is, can I make a call through the FileSystemObjec t or a Folder
                object to get just the files that start with the letter 'A' for
                example?
                >
                The only API I can see is Folder.Files which gives *all* the files
                then I would have to sort through and do the pattern matching myself
                which seems like it will be very slow. Any ideas?
                >
                Thanks in advance,
                Chrisso
                >

                Comment

                Working...