468,288 Members | 1,985 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,288 developers. It's quick & easy.

os.listdir(<file specifications>) doesn't work ??

hello,

I want to find all files with the extension "*.txt".
From the examples in "Learning Python, Lutz and Asher" and
from the website I see examples where you also may specify a wildcard filegroup.

But when I try this
files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')

I get an error message

WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect:
'D:\\akto_yk\\yk_controle\\*.txt/*.*'

What am I doing wrong ?

thanks,
Stef Mientki
May 14 '07 #1
6 16948
On May 14, 4:09 pm, Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
wrote:
hello,

I want to find all files with the extension "*.txt".
From the examples in "Learning Python, Lutz and Asher" and
from the website I see examples where you also may specify a wildcard filegroup.

But when I try this
files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')

I get an error message

WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect:
'D:\\akto_yk\\yk_controle\\*.txt/*.*'

What am I doing wrong ?

thanks,
Stef Mientki
You want the glob module

http://docs.python.org/lib/module-glob.html

import glob
glob.glob('*.txt')
May 14 '07 #2
timw.google wrote:
On May 14, 4:09 pm, Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
wrote:
>hello,

I want to find all files with the extension "*.txt".
From the examples in "Learning Python, Lutz and Asher" and
from the website I see examples where you also may specify a wildcard filegroup.

But when I try this
files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')

I get an error message

WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect:
'D:\\akto_yk\\yk_controle\\*.txt/*.*'

What am I doing wrong ?

thanks,
Stef Mientki

You want the glob module

http://docs.python.org/lib/module-glob.html

import glob
glob.glob('*.txt')
thanks that works !
Still don't know why it's not allowed through listdir ;-)

cheers,
Stef Mientki
May 14 '07 #3
Hi!

You want the glob module
Warning: glob has "unix like behavior"; just a little different with
windows's DIR


--
@-salutations

Michel Claveau
May 14 '07 #4
En Mon, 14 May 2007 18:24:23 -0300, Stef Mientki
<S.**************@mailbox.kun.nlescribió:
>> files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')

I get an error message

WindowsError: [Errno 123] The filename, directory name, or volume
label syntax is incorrect:
'D:\\akto_yk\\yk_controle\\*.txt/*.*'
Still don't know why it's not allowed through listdir ;-)
Because listir expects a single directory as parameter, not a wildcard
specification.
That is, you could do:
files = os.listdir("D:\\akto_yk\\yk_controle")
to get ALL the filenames in that directory, and then filter them using
fnmatch. But that's exactly what the glob module does internally.

--
Gabriel Genellina

May 14 '07 #5
Michel Claveau wrote:
Hi!

>You want the glob module

Warning: glob has "unix like behavior"; just a little different with
windows's DIR
Don't know the details of "Unix"
but I thought "unix" was case-sensitive,
and glob.glob doesn't seem to be,
at least not on windows systems ;-)

cheers,
Stef Mientki
May 14 '07 #6
The case sensitivity has to do with the OS you're on. So, using glob
from Un*x is case sensitive, but from Windows it isn't.
-----Original Message-----
From: py*****************************************@python .org
[mailto:py***************************************** @python.org] On
Behalf Of Stef Mientki
Sent: Monday, May 14, 2007 3:39 PM
To: py*********@python.org
Subject: Re: os.listdir(<file specifications>) doesn't work ??

Michel Claveau wrote:
Hi!

>You want the glob module

Warning: glob has "unix like behavior"; just a little different with
windows's DIR
Don't know the details of "Unix"
but I thought "unix" was case-sensitive,
and glob.glob doesn't seem to be,
at least not on windows systems ;-)

cheers,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list
May 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Juna | last post: by
3 posts views Thread by jx2 | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.