-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.py
More file actions
27 lines (18 loc) · 851 Bytes
/
scanner.py
File metadata and controls
27 lines (18 loc) · 851 Bytes
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
import os
# Recursively scans a directory and returns files matching given extensions
def scan_directory(path, scanned_extensions):
files = []
if not os.path.isdir(path):
return files
normalized_extensions = [ext.lower().lstrip('.') for ext in scanned_extensions if ext]
# Walk through all directories and subdirectories
for root, dirs, filenames in os.walk(path):
# Iterate over all files in current directory
for f in filenames:
# Check file against all target extensions
for extension in normalized_extensions:
# Case-insensitive extension match (e.g. .exe, .dll)
if f.lower().endswith(f".{extension}"):
# Store full absolute path to matched file
files.append(os.path.join(root, f))
return files