473,388 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 8720
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jason Kratz | last post by:
OK. I've search on google groups and around the web for this and I haven't found an answer. I'm a Python newbie and have what I assume is a basic question. os.listdir takes a pathname as an arg...
8
by: Hannu Kankaanp?? | last post by:
This may be a bug or simply a strange result of undefined behaviour, but this is what I get with Python 2.3.2 on Windows XP: >>> import os >>> os.listdir('') >>> os.listdir(u'')
0
by: Ishwor | last post by:
hi check your seperator variable in the os module. :) for example >>> import os >>> os.sep '\\' Now what you do is :- >> os.listdir("D:" + os.sep + "any_other_folder_name" + os.sep); :)
7
by: Kenneth Pronovici | last post by:
I have some confusion regarding the relationship between locale, os.listdir() and unicode pathnames. I'm running Python 2.3.5 on a Debian system. If it matters, all of the files I'm dealing with...
15
by: Riccardo Galli | last post by:
Hi, I noticed that when I use os.listdir I need to work with absolute paths 90% of times. While I can use a for cycle, I'd prefere to use a list comprehension, but it becomes too long. I...
2
by: Thomas Thomas | last post by:
Hi All, I am trying to access a mapped network drive folder. everything works fine normally. But when i run the application as service I am getting the error Traceback (most recent call last):...
2
by: robert | last post by:
I want to get the files and sizes and times etc. stats of a dir fast. os.listdir & iterating with os.stat seems not to run at optimal speed for network folders. Is there a faster possibility? (both...
6
by: Soren | last post by:
Hi, I'd like to read the filenames in a directory, but not the subdirectories, os.listdir() gives me everything... how do I separate the directory names from the filenames? Is there another way...
6
by: jimgardener | last post by:
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 ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.