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

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon May 14 17:35:15 EDT 2007


En Mon, 14 May 2007 18:24:23 -0300, Stef Mientki  
<S.Mientki-nospam at mailbox.kun.nl> escribió:

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




More information about the Python-list mailing list