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

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 17341
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: | last post by:
Hello, I hope someone will help me or I will have to dive from 11th floor. Why this --> test = @"Melanie "Jets" Riggs" doesnt work in asp? I need something like that and I dont know how to make it...
1
by: Station Media | last post by:
Hi, here my problem, i use stored procedure in ACCESS database(latest version), and i would like to use this procedure but it doesnt work, do you know why ? Procedure: PARAMETERS MyField Text...
3
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am...
0
by: Juna | last post by:
I have been working in vs2003, but now started to work in vs2005 but the problem, I have simple web application not website, which work i mean open in browser when we press F5 or run the...
1
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set...
3
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
1
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
20
by: Hush | last post by:
Hi, The following code works fine in IE7 but FF returns with an error: Access denied to achieve the property Element.firstChild. In this line: nodes = xmlDoc.documentElement.childNodes; My...
9
by: AGP | last post by:
I've been scratching my head for weeks to understand why some code doesnt work for me. here is what i have: dim sVal as string = "13.2401516" dim x as double x = sVal debug.writeline ( x)
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.