473,651 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\pgmgall ery" # where i have pgm files
g2=listdir(pgmd ir)

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

i am running python on winXP ..can anyone tell me why i get this
error?
Jun 27 '08 #1
6 3758
>
i get the following error
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\pyth on\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\\pytho n\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\pgmgall ery" # where i have pgm files
g2=listdir(pgmd ir)

i get the following error
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\pyth on\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:\cod e\python\pgmgal lery"
?

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*****@virgil io.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:\cod e\python\pgmgal lery" # where i have pgm files
g2=listdir(pgm dir)

i get the following error
WindowsError : [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'f:\\code\\pyth on\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:\cod e\python\pgmgal lery"
?

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\\pytho n\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.howev er 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*********@gm ail.comwrote:
>
* Run cmd.exe and see if you can run "dir f:\\code\\pytho n\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...@gm ail.comwrote:
** Run cmd.exe and see if you can run "dir f:\\code\\pytho n\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
3332
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 charcters in it, that the code needs to run until all bad characters are gone? For example, if a file has the name "<bad*mac\file" the program has to run 3 times to get all three bad chars out of the file name. The passes look like this:
8
2445
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
1409
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
2572
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 propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. This would bring only advantages, I think.
1
3257
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 Python Library Reference). I work with python version 2.2. Now my 2 questions: Why does dircache.listdir() work different?
0
8361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7299
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.