|
1
2
3
4
5
6
7
|
import os
import fnmatch
def find_pattern_all(pattern, path, casesensitive):
result = []
for root, dirs, files in os.walk(path):
for name in files:
|
|
8
|
if casesensitive:
|
|
9
10
|
if fnmatch.fnmatchcase(name,pattern):
result.append(os.path.join(root, name))
|
|
11
|
else:
|
|
12
13
14
15
16
17
18
|
if fnmatch.fnmatch(name.lower(), pattern.lower()):
result.append(os.path.join(root, name))
return result
def find_pattern(pattern, path, casesensitive):
for root, dirs, files in os.walk(path):
for name in files:
|
|
19
|
if casesensitive:
|
|
20
21
|
if fnmatch.fnmatchcase(name,pattern):
return os.path.join(root, name)
|
|
22
|
else:
|
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
if fnmatch.fnmatch(name.lower(), pattern.lower()):
return os.path.join(root, name)
return None
def find_all(name, path):
result = []
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
return result
def find(name, path):
for root, dirs, files in os.walk(path):
if name in files:
return os.path.join(root, name)
return None
|