-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstringSearch.py
86 lines (60 loc) · 2.54 KB
/
stringSearch.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import csv
def search_files(folder_path):
matching_files = []
# Walk through the directory
for root, dirs, files in os.walk(folder_path):
for file in files:
# Check if the file ends with '.bdf' and contains 'npu'
if file.endswith('.bdf') and 'npu' in file.lower():
# Add the full path of the file to the list
matching_files.append(os.path.join(root, file))
return matching_files
def search_files_lst(folder_path):
matching_files = []
# Walk through the directory
for root, dirs, files in os.walk(folder_path):
for file in files:
# Check if the file ends with '.bdf' and contains 'lst'
if file.endswith('.bdf') and 'lst' in file.lower():
# Add the full path of the file to the list
matching_files.append(os.path.join(root, file))
return matching_files_lst
def search_files_ern(folder_path):
matching_files = []
# Walk through the directory
for root, dirs, files in os.walk(folder_path):
for file in files:
# Check if the file ends with '.bdf' and contains 'ern'
if file.endswith('.bdf') and 'ern' in file.lower():
# Add the full path of the file to the list
matching_files.append(os.path.join(root, file))
return matching_files_ern
# Specify the folder path you want to search
folder_to_search = 'C:\Users\John\Documents\MATLAB\soarCinci\'
# Call the function and get the list of matching files
result = search_files(folder_to_search)
resultLst = search_files_lst(folder_to_search)
resultErn = search_files_ern(folder_to_search)
# Print the list of matching files
if result:
print("Files containing 'npu' and ending with '.bdf':")
for file in result:
print(file)
else:
print("No matching files found for NPU.")
with open("outputNpu.csv", "w", newline='') as csvfile:
# Create a CSV writer object
writer = csv.writer(csvfile)
# Write the fieldnames (column headers)
writer.writerow(result)
with open("outputLst.csv", "w", newline='') as csvfile:
# Create a CSV writer object
writer = csv.writer(csvfile)
# Write the fieldnames (column headers)
writer.writerow(resultLst)
with open("outputErn.csv", "w", newline='') as csvfile:
# Create a CSV writer object
writer = csv.writer(csvfile)
# Write the fieldnames (column headers)
writer.writerow(resultErn)