-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindMissingFileNumbersOptimized_10000.py
53 lines (47 loc) · 1.88 KB
/
FindMissingFileNumbersOptimized_10000.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
#! /usr/bin/env/python
import mmap
import re
#-------------------------------------------------------------------------------------------
# Main Function
#-------------------------------------------------------------------------------------------
def main():
filePath = input("Enter file path: ")
endFileNum = input("Enter end file number: ")
filesMissingCount = 0
filesPresentCount = 0
fileNumbersMissing = set()
filesNumbersPresent = set()
fileNamesPresent = set()
#>>> myRegex=r'(.*)file_(.)' + re.escape(str(TEXTTO)) + r'\.txt'
#>>> searchObj=re.search(myRegex,line)
#>>> print(searchObj)
#<_sre.SRE_Match object; span=(0, 15), match='asdffile__0.txt'>
# https://stackoverflow.com/questions/46476537/python-how-to-search-a-string-in-a-large-file
#my_regex = re.compile('.*file_.(\d+)\.txt.*')
my_regex = re.compile('.*file(\d+)\.txt.*')
for line in open(filePath):
match = my_regex.search(line)
if match:
filesNumbersPresent.add(int(match.group(1)))
#start = line.find('file_')
start = line.find('file')
end = line.find('txt', start)
fileNamesPresent.add(line[start:end+3])
for x in range(int(endFileNum)):
if x not in filesNumbersPresent:
fileNumbersMissing.add(x)
filesMissingCount += 1
else:
filesPresentCount += 1
print("Files Present: ")
#print(fileNamesPresent)
#print(filesNumbersPresent)
print("Files Present Count: %d" % filesPresentCount)
print("Files Missing: ")
print(fileNumbersMissing)
print("Files Missing Count: %d" % filesMissingCount)
#-------------------------------------------------------------------------------------------
# Start Main
#-------------------------------------------------------------------------------------------
if __name__ == "__main__":
main()