473,386 Members | 1,830 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,386 software developers and data experts.

problem with listdir

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

pgmdir="f:\code\python\pgmgallery" # where i have pgm files
g2=listdir(pgmdir)

i get the following error
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\python\pgmgallery/*.*'

i am running python on winXP ..can anyone tell me why i get this
error?
Jun 27 '08 #1
6 3742
>
i get the following error
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\python\pgmgallery/*.*'

i am running python on winXP ..can anyone tell me why i get this
error?
--
>From some Googling, it looks like this error can happen in Windows
when you have registry problems. This isn't a Python problem as far as
I can tell.

A few things for you to try:

* Try running your code on another machine with the same directory.

* Run cmd.exe and see if you can run "dir f:\\code\\python\pgmgallery/*.*"

* Try using other drives besides F: (C: is a good start)

* Try using other directories under F: drive in your program and see
when you start hitting the problem.

David.
Jun 27 '08 #2
On Sat, 26 Apr 2008 01:24:23 -0700, jimgardener wrote:
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

pgmdir="f:\code\python\pgmgallery" # where i have pgm files
g2=listdir(pgmdir)

i get the following error
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\python\pgmgallery/*.*'

i am running python on winXP ..can anyone tell me why i get this
error?
Did you try using a raw string as pathname
pgmdir=r"f:\code\python\pgmgallery"
?

AFAIK, the character '\' in interpreted in Python as the beginning of
an escape sequence (such as '\n') and it should be doubled ( as in the
error message) or a raw string should be used, telling Python that there
are no escape sequences inside.
However, from the message it looks like the path as been understood as
such, so this might not be the case.

Ciao
-----
FB
Jun 27 '08 #3
On Sat, 26 Apr 2008 19:07:45 +1000, Francesco Bochicchio
<bo*****@virgilio.itwrote:
On Sat, 26 Apr 2008 01:24:23 -0700, jimgardener wrote:
>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

pgmdir="f:\code\python\pgmgallery" # where i have pgm files
g2=listdir(pgmdir)

i get the following error
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\python\pgmgallery/*.*'

i am running python on winXP ..can anyone tell me why i get this
error?

Did you try using a raw string as pathname
pgmdir=r"f:\code\python\pgmgallery"
?

AFAIK, the character '\' in interpreted in Python as the beginning of
an escape sequence (such as '\n') and it should be doubled ( as in the
error message) or a raw string should be used, telling Python that there
are no escape sequences inside.
However, from the message it looks like the path as been understood as
such, so this might not be the case.

Ciao
-----
FB
Neither \c nor \p are escape characters in Section 2.4.1 "String literals".

Could there be some files in that directory whose name is not a valid
Windows file name? Windows file names cannot have the following symbols:

\ / : * ? " < |

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>
Jun 27 '08 #4
* Run cmd.exe and see if you can run "dir f:\\code\\python\pgmgallery/*.*"
that causes a message 'Invalid switch - "*.*".'
* Try using other directories under F: drive in your program and seewhen you start hitting the problem.
i tried that..on some directories in the same drive this gives
correct result and returns a list of filenames.however the error
occurs on other directories ,looks like a weird windows problem!
Jun 27 '08 #5
On Sat, Apr 26, 2008 at 7:56 PM, jimgardener <ji*********@gmail.comwrote:
>
* Run cmd.exe and see if you can run "dir f:\\code\\python\pgmgallery/*.*"
>

that causes a message 'Invalid switch - "*.*".'

Probably because on the command-line, / means a command-line option.
Been a while since I used DOS.

Try this instead:

dir f:\code\python\pgmgallery\*.*"

David.
Jun 27 '08 #6
On Apr 27, 1:57*am, David <wizza...@gmail.comwrote:
On Sat, Apr 26, 2008 at 7:56 PM, jimgardener <jimgarde...@gmail.comwrote:
** Run cmd.exe and see if you can run "dir f:\\code\\python\pgmgallery/*.*"
*that causes a message 'Invalid switch - "*.*".'

Probably because on the command-line, / means a command-line option.
Been a while since I used DOS.

Try this instead:

dir f:\code\python\pgmgallery\*.*"

David.
Try typing listdir( '.' ), which is Windows for 'the current path
[being used]', at an interpreter. listdir does not accept wildcards,
(surmisably since reg.exes are more powerful) and try ending with a
slash.

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
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'')
6
by: vegetax | last post by:
I am trying to make convert a directory "tree" in a list of list, but cant find the algoritm =( ,for example a directory tree like : +root  +doc    ele1    ele2    +doc3     ele3  +doc2
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...
1
by: kai | last post by:
Hello, I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000 listdir() will re-read the directory structure! But on AIX, listdir() will not re-read the directory structure (see...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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...

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.