problem with listdir

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

    problem with listdir

    hi
    i have a directory containing .pgm files of P5 type.i wanted to read
    the pixel values of these files ,so as a firststep i wrote code to
    make a list of filenames using listdir

    pgmdir="f:\code \python\pgmgall ery" # where i have pgm files
    g2=listdir(pgmd ir)

    i get the following error
    WindowsError: [Error 123] The filename, directory name, or volume
    label syntax is incorrect: 'f:\\code\\pyth on\pgmgallery/*.*'

    i am running python on winXP ..can anyone tell me why i get this
    error?
  • David

    #2
    Re: problem with listdir

    >
    i get the following error
    WindowsError: [Error 123] The filename, directory name, or volume
    label syntax is incorrect: 'f:\\code\\pyth on\pgmgallery/*.*'
    >
    i am running python on winXP ..can anyone tell me why i get this
    error?
    --
    >From some Googling, it looks like this error can happen in Windows
    when you have registry problems. This isn't a Python problem as far as
    I can tell.

    A few things for you to try:

    * Try running your code on another machine with the same directory.

    * Run cmd.exe and see if you can run "dir f:\\code\\pytho n\pgmgallery/*.*"

    * Try using other drives besides F: (C: is a good start)

    * Try using other directories under F: drive in your program and see
    when you start hitting the problem.

    David.

    Comment

    • Francesco Bochicchio

      #3
      Re: problem with listdir

      On Sat, 26 Apr 2008 01:24:23 -0700, jimgardener wrote:
      hi
      i have a directory containing .pgm files of P5 type.i wanted to read
      the pixel values of these files ,so as a firststep i wrote code to
      make a list of filenames using listdir
      >
      pgmdir="f:\code \python\pgmgall ery" # where i have pgm files
      g2=listdir(pgmd ir)
      >
      i get the following error
      WindowsError: [Error 123] The filename, directory name, or volume
      label syntax is incorrect: 'f:\\code\\pyth on\pgmgallery/*.*'
      >
      i am running python on winXP ..can anyone tell me why i get this
      error?
      Did you try using a raw string as pathname
      pgmdir=r"f:\cod e\python\pgmgal lery"
      ?

      AFAIK, the character '\' in interpreted in Python as the beginning of
      an escape sequence (such as '\n') and it should be doubled ( as in the
      error message) or a raw string should be used, telling Python that there
      are no escape sequences inside.
      However, from the message it looks like the path as been understood as
      such, so this might not be the case.

      Ciao
      -----
      FB

      Comment

      • Kam-Hung Soh

        #4
        Re: problem with listdir

        On Sat, 26 Apr 2008 19:07:45 +1000, Francesco Bochicchio
        <bockman@virgil io.itwrote:
        On Sat, 26 Apr 2008 01:24:23 -0700, jimgardener wrote:
        >
        >hi
        >i have a directory containing .pgm files of P5 type.i wanted to read
        >the pixel values of these files ,so as a firststep i wrote code to
        >make a list of filenames using listdir
        >>
        >pgmdir="f:\cod e\python\pgmgal lery" # where i have pgm files
        >g2=listdir(pgm dir)
        >>
        >i get the following error
        >WindowsError : [Error 123] The filename, directory name, or volume
        >label syntax is incorrect: 'f:\\code\\pyth on\pgmgallery/*.*'
        >>
        >i am running python on winXP ..can anyone tell me why i get this
        >error?
        >
        Did you try using a raw string as pathname
        pgmdir=r"f:\cod e\python\pgmgal lery"
        ?
        >
        AFAIK, the character '\' in interpreted in Python as the beginning of
        an escape sequence (such as '\n') and it should be doubled ( as in the
        error message) or a raw string should be used, telling Python that there
        are no escape sequences inside.
        However, from the message it looks like the path as been understood as
        such, so this might not be the case.
        >
        Ciao
        -----
        FB
        Neither \c nor \p are escape characters in Section 2.4.1 "String literals".

        Could there be some files in that directory whose name is not a valid
        Windows file name? Windows file names cannot have the following symbols:

        \ / : * ? " < |

        --
        Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

        Comment

        • jimgardener

          #5
          Re: problem with listdir

          * Run cmd.exe and see if you can run "dir f:\\code\\pytho n\pgmgallery/*.*"
          >
          that causes a message 'Invalid switch - "*.*".'
          * Try using other directories under F: drive in your program and seewhen you start hitting the problem.
          i tried that..on some directories in the same drive this gives
          correct result and returns a list of filenames.howev er the error
          occurs on other directories ,looks like a weird windows problem!

          Comment

          • David

            #6
            Re: problem with listdir

            On Sat, Apr 26, 2008 at 7:56 PM, jimgardener <jimgardener@gm ail.comwrote:
            >
            * Run cmd.exe and see if you can run "dir f:\\code\\pytho n\pgmgallery/*.*"
            >
            >
            that causes a message 'Invalid switch - "*.*".'
            >
            >
            Probably because on the command-line, / means a command-line option.
            Been a while since I used DOS.

            Try this instead:

            dir f:\code\python\ pgmgallery\*.*"

            David.

            Comment

            • castironpi@gmail.com

              #7
              Re: problem with listdir

              On Apr 27, 1:57 am, David <wizza...@gmail .comwrote:
              On Sat, Apr 26, 2008 at 7:56 PM, jimgardener <jimgarde...@gm ail.comwrote:
              >
               * Run cmd.exe and see if you can run "dir f:\\code\\pytho n\pgmgallery/*.*"
              >
               that causes a message 'Invalid switch - "*.*".'
              >
              Probably because on the command-line, / means a command-line option.
              Been a while since I used DOS.
              >
              Try this instead:
              >
              dir f:\code\python\ pgmgallery\*.*"
              >
              David.
              Try typing listdir( '.' ), which is Windows for 'the current path
              [being used]', at an interpreter. listdir does not accept wildcards,
              (surmisably since reg.exes are more powerful) and try ending with a
              slash.

              Comment

              Working...