[Tutor] Replacement for 'Find' Module
Luis N
tegmine at gmail.com
Mon Aug 15 21:04:23 CEST 2005
On 8/15/05, Simon Gerber <nequeo at gmail.com> wrote:
> You could probably do something like this... (Note: This example is
> for Linux - but you can adapt it fairly easily to Windows.)
>
>
> # E.g. Find every .inf file on a CD-ROM.
> path = '/cdrom'
> # 'E:\\' or whatever for Windows....
> inf_list = []
> for root, dirs, files in os.walk(path):
> for current_file in files:
> if '.inf' in current_file:
if current_file.endswith('.inf'): #or current_file[:-4] might be more
appropriate, just my 2c
I wrote this in a script for limited globbing:
if cd:
toss = os.path.join(trashcan, os.path.split(i)[1])
pwd = os.getcwd()
else:
toss = os.path.join(trashcan, i)
if toss[-1] == '*':
crumple = []
if cd:
l = os.listdir(cd)
for i in l:
crumple.append(os.path.join(cd, i))
else:
crumple = os.listdir('.')
for i in crumple:
if i.startswith(toss[:-1]):
junk.append(i)
More information about the Tutor
mailing list