os.listdir(<file specifications>) doesn't work ??

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

    #1

    os.listdir(<file specifications>) doesn't work ??

    hello,

    I want to find all files with the extension "*.txt".
    From the examples in "Learning Python, Lutz and Asher" and
    from the website I see examples where you also may specify a wildcard filegroup.

    But when I try this
    files = os.listdir('D:\ \akto_yk\\yk_co ntrole\\*.txt')

    I get an error message

    WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect:
    'D:\\akto_yk\\y k_controle\\*.t xt/*.*'

    What am I doing wrong ?

    thanks,
    Stef Mientki
  • timw.google

    #2
    Re: os.listdir(&lt; file specifications& gt;) doesn't work ??

    On May 14, 4:09 pm, Stef Mientki <S.Mientki-nos...@mailbox. kun.nl>
    wrote:
    hello,
    >
    I want to find all files with the extension "*.txt".
    From the examples in "Learning Python, Lutz and Asher" and
    from the website I see examples where you also may specify a wildcard filegroup.
    >
    But when I try this
    files = os.listdir('D:\ \akto_yk\\yk_co ntrole\\*.txt')
    >
    I get an error message
    >
    WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect:
    'D:\\akto_yk\\y k_controle\\*.t xt/*.*'
    >
    What am I doing wrong ?
    >
    thanks,
    Stef Mientki
    You want the glob module

    Source code: Lib/glob.py The glob module finds pathnames using pattern matching rules similar to the Unix shell. No tilde expansion is done, but*,?, and character ranges expressed with[] will be co...


    import glob
    glob.glob('*.tx t')


    Comment

    • Stef Mientki

      #3
      Re: os.listdir(&lt; file specifications& gt;) doesn't work ??

      timw.google wrote:
      On May 14, 4:09 pm, Stef Mientki <S.Mientki-nos...@mailbox. kun.nl>
      wrote:
      >hello,
      >>
      >I want to find all files with the extension "*.txt".
      > From the examples in "Learning Python, Lutz and Asher" and
      >from the website I see examples where you also may specify a wildcard filegroup.
      >>
      >But when I try this
      > files = os.listdir('D:\ \akto_yk\\yk_co ntrole\\*.txt')
      >>
      >I get an error message
      >>
      > WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect:
      > 'D:\\akto_yk\\y k_controle\\*.t xt/*.*'
      >>
      >What am I doing wrong ?
      >>
      >thanks,
      >Stef Mientki
      >
      You want the glob module
      >
      Source code: Lib/glob.py The glob module finds pathnames using pattern matching rules similar to the Unix shell. No tilde expansion is done, but*,?, and character ranges expressed with[] will be co...

      >
      import glob
      glob.glob('*.tx t')
      thanks that works !
      Still don't know why it's not allowed through listdir ;-)

      cheers,
      Stef Mientki

      Comment

      • Michel Claveau

        #4
        Re: os.listdir(&lt; file specifications& gt;) doesn't work ??

        Hi!

        You want the glob module
        Warning: glob has "unix like behavior"; just a little different with
        windows's DIR






        --
        @-salutations

        Michel Claveau


        Comment

        • Gabriel Genellina

          #5
          Re: os.listdir(&lt; file specifications& gt;) doesn't work ??

          En Mon, 14 May 2007 18:24:23 -0300, Stef Mientki
          <S.Mientki-nospam@mailbox. kun.nlescribió:
          >> files = os.listdir('D:\ \akto_yk\\yk_co ntrole\\*.txt')
          >>>
          >>I get an error message
          >>>
          >> WindowsError: [Errno 123] The filename, directory name, or volume
          >>label syntax is incorrect:
          >> 'D:\\akto_yk\\y k_controle\\*.t xt/*.*'
          Still don't know why it's not allowed through listdir ;-)
          Because listir expects a single directory as parameter, not a wildcard
          specification.
          That is, you could do:
          files = os.listdir("D:\ \akto_yk\\yk_co ntrole")
          to get ALL the filenames in that directory, and then filter them using
          fnmatch. But that's exactly what the glob module does internally.

          --
          Gabriel Genellina

          Comment

          • Stef Mientki

            #6
            Re: os.listdir(&lt; file specifications& gt;) doesn't work ??

            Michel Claveau wrote:
            Hi!
            >
            >
            >You want the glob module
            >
            Warning: glob has "unix like behavior"; just a little different with
            windows's DIR
            Don't know the details of "Unix"
            but I thought "unix" was case-sensitive,
            and glob.glob doesn't seem to be,
            at least not on windows systems ;-)

            cheers,
            Stef Mientki

            Comment

            • Looney, James B

              #7
              RE: os.listdir(&lt; file specifications& gt;) doesn't work ??

              The case sensitivity has to do with the OS you're on. So, using glob
              from Un*x is case sensitive, but from Windows it isn't.


              -----Original Message-----
              From: python-list-bounces+james.b .looney=lmco.co m@python.org
              [mailto:python-list-bounces+james.b .looney=lmco.co m@python.org] On
              Behalf Of Stef Mientki
              Sent: Monday, May 14, 2007 3:39 PM
              To: python-list@python.org
              Subject: Re: os.listdir(<fil e specifications> ) doesn't work ??

              Michel Claveau wrote:
              Hi!
              >
              >
              >You want the glob module
              >
              Warning: glob has "unix like behavior"; just a little different with
              windows's DIR
              Don't know the details of "Unix"
              but I thought "unix" was case-sensitive,
              and glob.glob doesn't seem to be,
              at least not on windows systems ;-)

              cheers,
              Stef Mientki
              --

              Comment

              Working...