problem with listdir

J

jimgardener

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?
 
D

David

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.
 
K

Kam-Hung Soh

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

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:

\ / : * ? " < > |
 
J

jimgardener

* 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 see> when 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!
 
D

David

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.
 
C

castironpi

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top