annotate Lib/lib-old/find.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents a81b6db6d33c
children c3a096bfbd6b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2260
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 import fnmatch
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 import os
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 _debug = 0
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 _prune = ['(*)']
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 def find(pattern, dir = os.curdir):
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 list = []
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 names = os.listdir(dir)
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 names.sort()
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 for name in names:
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 if name in (os.curdir, os.pardir):
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 continue
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 fullname = os.path.join(dir, name)
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 if fnmatch.fnmatch(name, pattern):
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 list.append(fullname)
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 if os.path.isdir(fullname) and not os.path.islink(fullname):
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 for p in _prune:
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 if fnmatch.fnmatch(name, p):
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 if _debug: print "skip", `fullname`
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 break
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 else:
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 if _debug: print "descend into", `fullname`
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 list = list + find(pattern, fullname)
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 return list