Stef Mientki 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            
Hi Stef,
Like that name; from a passing thought, I think the os.listdir command will resolve the slash/backslash. You might try using the unix method which I think would be 'd:/akto_yk/yk_controls/*.txt'. I'm sorry, but I can't test this knowledge, as I don't have access to Windows.

Alternatively you could use glob.glob, after changing directory ( via os.chdir) to get a listing.

   from os import chdir, getcwd
   from glob import glob

   CWD = getcwd()
   chdir( 'd:/akto_yk/yk_controls')
   filelist = glob.glob('*.txt')
   chdir( CWD )


Steven Howe

--
HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to