472,117 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 software developers and data experts.

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

Aug 3 '07 #1
3 8410
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
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
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.

Similar topics

11 posts views Thread by Jason Kratz | last post: by
8 posts views Thread by Hannu Kankaanp?? | last post: by
reply views Thread by Ishwor | last post: by
7 posts views Thread by Kenneth Pronovici | last post: by
15 posts views Thread by Riccardo Galli | last post: by
2 posts views Thread by Thomas Thomas | last post: by
2 posts views Thread by robert | last post: by
6 posts views Thread by jimgardener | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.