os.listdir path error

Discussion in 'Python' started by vedrandekovic@v-programs.com, Aug 3, 2007.

  1. Guest

    Hello

    Here is my simple listdir example:

    >>> import os
    >>> os.listdir("C:\Python24\") # This directory relly exists


    Here is my error:

    WindowsError: [Errno 3] The system cannot find the path specified: 'l/
    *.*'

    Regards,
    Vedran
     
    , Aug 3, 2007
    #1
    1. Advertising

  2. Jerry Hill Guest

    On 8/3/07, <> wrote:
    > Hello
    >
    > Here is my simple listdir example:
    >
    > >>> import os
    > >>> os.listdir("C:\Python24\") # This directory relly exists

    >
    > Here is my error:
    >
    > WindowsError: [Errno 3] The system cannot find the path specified: 'l/
    > *.*'



    That's a somewhat surprising error. Under 2.5, I get a more helpful
    error message:

    >>> import os
    >>> os.listdir("C:\Python25\")


    SyntaxError: EOL while scanning single-quoted string

    That's because I've escaped the closing quote of the string with \".
    Use this instead:

    >>> os.listdir("C:\\Python25\\")

    or
    >>> os.listdir("C:/Python25/")


    since windows is usually happy to use forward slashes instead of
    backslashes in directory names.

    --
    Jerry
     
    Jerry Hill, Aug 3, 2007
    #2
    1. Advertising

  3. Guest

    On Aug 3, 2:50 pm, wrote:
    > Hello
    >
    > Here is my simple listdir example:
    >
    > >>> import os
    > >>> os.listdir("C:\Python24\") # This directory relly exists

    >
    > Here is my error:
    >
    > WindowsError: [Errno 3] The system cannot find the path specified: 'l/
    > *.*'
    >
    > Regards,
    > Vedran


    I get "SyntaxError: EOL while scanning single-quoted string", which is
    what should happen when you escape the double-quotes at the end. Not
    sure how you're getting that WindowsErrors.

    If I do os.listdir('c:\python24') instead, it works fine.

    Mike
     
    , Aug 3, 2007
    #3
  4. Tim Roberts Guest

    wrote:
    >
    >I get "SyntaxError: EOL while scanning single-quoted string", which is
    >what should happen when you escape the double-quotes at the end. Not
    >sure how you're getting that WindowsErrors.
    >
    >If I do os.listdir('c:\python24') instead, it works fine.


    Yes, but only by accident. It will fail again if you try to do
    os.listdir('c:\tmp'). You need to use the right quoting.
    --
    Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Aug 5, 2007
    #4
    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. kai
    Replies:
    1
    Views:
    383
  2. kai
    Replies:
    0
    Views:
    375
  3. kai
    Replies:
    0
    Views:
    319
  4. kai
    Replies:
    0
    Views:
    317
  5. PerOK
    Replies:
    2
    Views:
    1,446
    Per Olav Kroka
    Jan 8, 2009
Loading...

Share This Page