os.listdir path error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vedrandekovic@v-programs.com

    os.listdir path error

    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

  • Jerry Hill

    #2
    Re: os.listdir path error

    On 8/3/07, vedrandekovic@v-programs.com <vedrandekovic@ v-programs.comwro te:
    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

    Comment

    • kyosohma@gmail.com

      #3
      Re: os.listdir path error

      On Aug 3, 2:50 pm, vedrandeko...@v-programs.com 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 "SyntaxErro r: 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

      Comment

      • Tim Roberts

        #4
        Re: os.listdir path error

        kyosohma@gmail. com wrote:
        >
        >I get "SyntaxErro r: 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, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        Working...