Add more heuristics for search_accdb

This commit is contained in:
2023-05-02 00:05:08 +02:00
parent 0b857539b1
commit 8de8a88587

View File

@ -14,8 +14,7 @@ import pypyodbc
import csv import csv
IGNORED_PATHS = ['C:\\Windows'] IGNORED_NAMES = ['Windows', 'Program Files', 'Program Files (x86)', 'AppData']
IGNORED_NAMES = ['Program Files', 'Program Files (x86)', 'AppData']
def get_drives() -> List[str]: def get_drives() -> List[str]:
@ -31,14 +30,17 @@ def search_accdb(base_path: str = None) -> Generator[str, None, None]:
for drive in get_drives(): for drive in get_drives():
yield from search_accdb(f'{drive}:') yield from search_accdb(f'{drive}:')
return return
elif base_path.count('\\') >= 8:
return
try: try:
for entry in os.scandir(f'{base_path}\\'): entries = [e for e in os.scandir(f'{base_path}\\')]
for entry in entries:
path = f'{base_path}\\{entry.name}' path = f'{base_path}\\{entry.name}'
if path in IGNORED_PATHS or entry.name in IGNORED_NAMES: if entry.name in IGNORED_NAMES:
continue continue
if entry.is_file() and entry.name.lower().endswith('.accdb'): elif entry.is_file() and entry.name.lower().endswith('.accdb'):
yield path yield path
elif entry.is_dir() and not entry.is_symlink(): elif len(entries) <= 50 and entry.is_dir() and not entry.is_symlink():
yield from search_accdb(path) yield from search_accdb(path)
except PermissionError: except PermissionError:
pass pass