-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_search.py
More file actions
47 lines (46 loc) · 1.36 KB
/
file_search.py
File metadata and controls
47 lines (46 loc) · 1.36 KB
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
import os
import subprocess as sp
import fnmatch
output = []
def directory_search(path,extension):
error_log = open(path+"/error.log",'w')
output = depth_search(path,extension,error_log)
error_log.close()
return output
def depth_search(path,extension,error_log):
dirs = os.listdir(path)
#print(dirs)
if len(dirs)==0:
error_log.write("Warning: "+path+" No file exist of extension "+extension+"\n")
return
count =0
for file in dirs:
index=file.find('~')
if index ==-1:
dec = os.path.isfile(path+"/"+file)
#print(dec)
if dec is True:
if fnmatch.fnmatch(file,extension):
tmp = []
tmp.append(path+"/"+file)
tmp.append(file)
output.append(tmp)
count = count+1
#print(file)
else:
#print(file)
depth_search(path+"/"+file,extension,error_log)
if count == 0:
error_log.write("Warning: "+path+" No file exist of extension "+extension+"\n")
return output
if __name__ == "__main__":
path=sp.getoutput('pwd')
extension ="*.bpel"
print(directory_search(path,extension))
'''
Multiple Line Comment
for i in output:
for j in i:
print(j," ")
print()
'''