Directory.GetFiles() Problem

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

    Directory.GetFiles() Problem

    Hi,
    Is it just me or does the search pattern parameter in Directory.GetFi les()
    have a problem with the '?' character?

    '*.*' works to find all files, but '?.*' does not work to find all files
    that have only a one letter (and infinite extension size) filename. In fact,
    it seems to act the same as '*.*'...

    Is this by design?

    Thanks in advance.


  • Alex Meleta

    #2
    Re: Directory.GetFi les() Problem

    Hi Julie,

    No, it's not by design, it should work. How do you use it coz that should
    work: Directory.GetFi les(<path>, "*.tx?") // or "?n.*"

    Regards, Alex Meleta
    [TechBlog] http://devkids.blogspot.com



    JSHi,
    JSIs it just me or does the search pattern parameter in
    JSDirectory.Get Files()
    JShave a problem with the '?' character?
    JS'*.*' works to find all files, but '?.*' does not work to find all
    JSfiles that have only a one letter (and infinite extension size)
    JSfilename. In fact, it seems to act the same as '*.*'...
    JS>
    JSIs this by design?
    JS>
    JSThanks in advance.
    JS>


    Comment

    • Daniel Bass

      #3
      Re: Directory.GetFi les() Problem


      What version of .Net are you using? I've just tried this in .Net 2.0 (VS
      2005) and it works as expected... Only files that had exactly one character
      before the point (.) were listed.

      Dim listOfFiles As String() = Directory.GetFi les("C:\", "?.*")
      For Each filename As String In listOfFiles
      Console.WriteLi ne(filename)
      Next



      "Julie Smith" <julie@home.com wrote in message
      news:OPOCu2nwHH A.936@TK2MSFTNG P02.phx.gbl...
      Hi,
      Is it just me or does the search pattern parameter in Directory.GetFi les()
      have a problem with the '?' character?
      >
      '*.*' works to find all files, but '?.*' does not work to find all files
      that have only a one letter (and infinite extension size) filename. In
      fact, it seems to act the same as '*.*'...
      >
      Is this by design?
      >
      Thanks in advance.
      >

      Comment

      • Julie Smith

        #4
        Re: Directory.GetFi les() Problem

        I have constructed a string pattern for each day (DDMMYYxx.txt). So, for
        example the string pattern for today is "110707xx.t xt". The search string I
        use is "110707??.t xt". However, it picked up a file called "1107071.tx t". As
        you can see, that only fills one ?, not both.

        I find this very weird. I might do some test scripts to see if I can
        reproduce it outside my application.


        "Alex Meleta" <ameleta@gmail. comwrote in message
        news:150f6b3027 6978c99105d8075 34a@msnews.micr osoft.com...
        Hi Julie,
        >
        No, it's not by design, it should work. How do you use it coz that should
        work: Directory.GetFi les(<path>, "*.tx?") // or "?n.*"
        >
        Regards, Alex Meleta
        [TechBlog] http://devkids.blogspot.com
        >
        >
        >
        JSHi,
        JSIs it just me or does the search pattern parameter in
        JSDirectory.Get Files()
        JShave a problem with the '?' character?
        JS'*.*' works to find all files, but '?.*' does not work to find all
        JSfiles that have only a one letter (and infinite extension size)
        JSfilename. In fact, it seems to act the same as '*.*'...
        JSJSIs this by design?
        JSJSThanks in advance.
        JS>
        >

        Comment

        • Julie Smith

          #5
          Re: Directory.GetFi les() Problem

          Well, I ran two simulations:
          string[] files = Directory.GetFi les(dir, "100707??.c nc",
          SearchOption.Al lDirectories);
          foreach (string s in files)
          Console.WriteLi ne(s);

          This returned:
          \1007070.CNC
          \10070701.CNC
          \10070702.CNC
          \10070703.CNC
          \10070704.CNC
          \10070705.CNC
          \10070706.CNC
          \10070707.CNC
          \1007071.CNC
          \1007072.CNC

          As you can see, its not working as expected... However, changing the search
          string to "100707?.cn c":
          string[] files = Directory.GetFi les(dir, "100707?.cn c",
          SearchOption.Al lDirectories);

          This produces:
          \1007070.CNC
          \1007071.CNC
          \1007072.CNC

          This works as expected.

          This is .NET 2.0 btw :-)


          Comment

          • Julie Smith

            #6
            Re: Directory.GetFi les() Problem

            It is .net 2.0. My previous post to Alex shows my problem with it not
            working when two ? are used together. Referring to your example, what if
            your search string was "??.*", would it only list files with TWO characters
            before the period?


            "Daniel Bass" <danREMOVEbass@ blueCAPSbottle. comFIRSTwrote in message
            news:ekk$ecwwHH A.3684@TK2MSFTN GP02.phx.gbl...
            >
            What version of .Net are you using? I've just tried this in .Net 2.0 (VS
            2005) and it works as expected... Only files that had exactly one
            character before the point (.) were listed.
            >
            Dim listOfFiles As String() = Directory.GetFi les("C:\", "?.*")
            For Each filename As String In listOfFiles
            Console.WriteLi ne(filename)
            Next
            >
            >
            >
            "Julie Smith" <julie@home.com wrote in message
            news:OPOCu2nwHH A.936@TK2MSFTNG P02.phx.gbl...
            >Hi,
            >Is it just me or does the search pattern parameter in
            >Directory.GetF iles() have a problem with the '?' character?
            >>
            >'*.*' works to find all files, but '?.*' does not work to find all files
            >that have only a one letter (and infinite extension size) filename. In
            >fact, it seems to act the same as '*.*'...
            >>
            >Is this by design?
            >>
            >Thanks in advance.
            >>
            >
            >

            Comment

            • Daniel Bass

              #7
              Re: Directory.GetFi les() Problem

              No. It would list files with none, one or two characters before the dot (.)


              "Julie Smith" <julie@home.com wrote in message
              news:OBWjquzwHH A.736@TK2MSFTNG P06.phx.gbl...
              It is .net 2.0. My previous post to Alex shows my problem with it not
              working when two ? are used together. Referring to your example, what if
              your search string was "??.*", would it only list files with TWO
              characters before the period?
              >
              >
              "Daniel Bass" <danREMOVEbass@ blueCAPSbottle. comFIRSTwrote in message
              news:ekk$ecwwHH A.3684@TK2MSFTN GP02.phx.gbl...
              >>
              >What version of .Net are you using? I've just tried this in .Net 2.0 (VS
              >2005) and it works as expected... Only files that had exactly one
              >character before the point (.) were listed.
              >>
              > Dim listOfFiles As String() = Directory.GetFi les("C:\", "?.*")
              > For Each filename As String In listOfFiles
              > Console.WriteLi ne(filename)
              > Next
              >>
              >>
              >>
              >"Julie Smith" <julie@home.com wrote in message
              >news:OPOCu2nwH HA.936@TK2MSFTN GP02.phx.gbl...
              >>Hi,
              >>Is it just me or does the search pattern parameter in
              >>Directory.Get Files() have a problem with the '?' character?
              >>>
              >>'*.*' works to find all files, but '?.*' does not work to find all files
              >>that have only a one letter (and infinite extension size) filename. In
              >>fact, it seems to act the same as '*.*'...
              >>>
              >>Is this by design?
              >>>
              >>Thanks in advance.
              >>>
              >>
              >>
              >
              >

              Comment

              • Rad [Visual C# MVP]

                #8
                Re: Directory.GetFi les() Problem

                On Tue, 10 Jul 2007 09:06:35 +1000, "Julie Smith" <julie@home.com >
                wrote:
                >Hi,
                >Is it just me or does the search pattern parameter in Directory.GetFi les()
                >have a problem with the '?' character?
                >
                >'*.*' works to find all files, but '?.*' does not work to find all files
                >that have only a one letter (and infinite extension size) filename. In fact,
                >it seems to act the same as '*.*'...
                >
                >Is this by design?
                >
                >Thanks in advance.
                >
                I believe it is by design. Clearly you're an old hand at the DOS
                prompt where ? meant a single character as opposed to .NET where it
                means zero or one

                --

                Comment

                • hello

                  #9
                  HI,is that a bug of .net when using ?? inDirectory.Get Files search pattern?

                  I wrote a simple test program, and I found that ?? works like *. I dont know why.

                  If ? means 0 or 1 character, but why did files ending with more than 2 characters show in the results, when I searched for something like "abc??.txt" in the directory? I did not work as doc.

                  Comment

                  • Tim Roberts

                    #10
                    Re: HI,is that a bug of .net when using ?? in Directory.GetFi les search pattern?

                    hello wrote:
                    >
                    >I wrote a simple test program, and I found that ?? works like *. I
                    >dont know why.
                    >
                    >If ? means 0 or 1 character, but why did files ending with more than
                    >2 characters show in the results, when I searched for something like
                    >"abc??.txt" in the directory? I did not work as doc.
                    Can you be more precise about exactly what you tried, and exactly what you
                    expected? Include a "dir" so we can see what the directory looked like. I
                    just tried an example, where ? and ?? did exactly what they were supposed
                    to.

                    Also, see if the "dir" command provides the same results with the same
                    glob.
                    --
                    Tim Roberts, timr@probo.com
                    Providenza & Boekelheide, Inc.

                    Comment

                    Working...