-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind.py
64 lines (50 loc) · 1.3 KB
/
find.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import re
import sys
from os import walk
def main(pattern:str):
for filePath,dirName,files in walk('.'):
for file in files:
file = os.path.join(filePath,file)
text = open_file(file)
try:
match = search(pattern,text)
except TypeError as e:
match = None
if match is not None:
print("+",file)
# os.system('pause')
def open_file(file_name):
try:
with open(file_name,"r") as f:
try:
text = f.read()
return text
except UnicodeDecodeError as e:
pass
except:
pass
def search(pattern:str,text:str):
pat = re.compile(pattern)
match = pat.search(text)
return match
def head_process(argvs:list):
all_argvs = ' '
all_argvs.join(argvs)
print(all_argvs)
if __name__ == '__main__':
print('-'*80)
print('/'+'-'*78+'\\')
fd = 'find'
argvs = [i for i in sys.argv]
del argvs[0]
for i in argvs:
fd+=' '+i
print('|',fd.center(78,' '),'|')
print('\\'+'-'*78+'/')
print('='*80)
head_process(sys.argv)
del sys.argv[0]
for i in sys.argv:
print('{}'.format(i).center(80,'='))
main(i)