<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Stef Mientki wrote:
<blockquote cite="mid:ba349$4648c142$d443bb3a$30299@news.speedlinq.nl"
type="cite">
<pre wrap="">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
</pre>
</blockquote>
Hi Stef,<br>
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.<br>
<br>
Alternatively you could use glob.glob, after changing directory ( via
os.chdir) to get a listing. <br>
<blockquote>from os import chdir, getcwd<br>
from glob import glob<br>
<br>
CWD = getcwd()<br>
chdir( 'd:/akto_yk/yk_controls')<br>
filelist = glob.glob('*.txt')<br>
chdir( CWD )<br>
</blockquote>
<br>
Steven Howe<br>
<br>
<pre class="moz-signature" cols="72">--
HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
</pre>
</body>
</html>