423,850 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,850 IT Pros & Developers. It's quick & easy.

os.listdir path error

P: n/a
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 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 8/3/07, ve***********@v-programs.com <ve***********@v-programs.comwrote:
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
Aug 3 '07 #2

P: n/a
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 "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 '07 #3

P: n/a
ky******@gmail.com 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, ti**@probo.com
Providenza & Boekelheide, Inc.
Aug 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.