-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (26 loc) · 1.02 KB
/
utils.py
File metadata and controls
32 lines (26 loc) · 1.02 KB
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
import os
from collections import deque
async def find_dll_directory(directory, files_to_search):
"""
Find directory containing any of the target files using Breadth-First Search.
Returns the directory closest to the root that contains any target file.
"""
if not os.path.isdir(directory):
return None
target_files = {os.path.basename(f) for f in files_to_search}
queue = deque([(directory, 0)])
visited = {directory}
while queue:
current_dir, depth = queue.popleft()
try:
files = os.listdir(current_dir)
if any(f in target_files for f in files):
return current_dir
for item in files:
full_path = os.path.join(current_dir, item)
if os.path.isdir(full_path) and full_path not in visited:
queue.append((full_path, depth + 1))
visited.add(full_path)
except (PermissionError, OSError):
continue
return None