I am reading a set of binary files (some, not all) recursively in a directory structure. These files are now-ancient Visual Foxpro files of various types.
Using a tool like TextWrangler, it finds all the occurrences of the search string.
Yet, in my python code (I'm still a semi-newbie), it misses some. Not sure why.
I've defined the search term like this: search_term = b'permissionlevel'
The code is pretty simple, but I'm missing something. I also experimented with reading the binary files in 1024 byte chunks (and other buffer lengths), but that did no better (worse, actually).
The python code catches 374 matches of the search term, when the correct number is 430 (as shown by two other search programs).
If anyone can see what I might be doing wrong, I would really appreciate that. :)
Thanks,
-------------------------
Using a tool like TextWrangler, it finds all the occurrences of the search string.
Yet, in my python code (I'm still a semi-newbie), it misses some. Not sure why.
I've defined the search term like this: search_term = b'permissionlevel'
The code is pretty simple, but I'm missing something. I also experimented with reading the binary files in 1024 byte chunks (and other buffer lengths), but that did no better (worse, actually).
The python code catches 374 matches of the search term, when the correct number is 430 (as shown by two other search programs).
If anyone can see what I might be doing wrong, I would really appreciate that. :)
Thanks,
-------------------------
fileCount = 0 totalMatches = 0 count = 0 for dirName, subdirlist, filelist in os.walk(path): print('Found directory: ' + dirName) for file in filelist: fileCount += 1 filePath = os.path.join(dirName, file) # print("\n***OPENING FILE***" + filePath + "\n") with open(filePath, 'rb') as f: lines = f.readlines() for line in lines: if line.upper().find(search_term.upper()) != -1: totalMatches += 1 count += 1 print(line) if (count > 0): print("Found " + str(count) + " match(es) in " + filePath) count = 0 # next file, please... print("\n" + str(fileCount) + " files found.") print("\n" + str(totalMatches) + " Total matches.")