forked from openedx/docs.openedx.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_map.py
executable file
·39 lines (29 loc) · 1.34 KB
/
image_map.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
import os
import subprocess
def grep_for_filenames(source_dir, search_dir):
# Loop through each file in the source directory
for root, dirs, files in os.walk(source_dir):
for file_name in files:
# Define the full path to the current file
file_path = os.path.join(root, file_name)
# Get the base file name (without path) to search for it
base_file_name = os.path.basename(file_path)
print(f"Searching for '{base_file_name}' in {search_dir}...")
# Use subprocess to call grep recursively in the target directory
result = subprocess.run(
["grep", "-rl", base_file_name, search_dir],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
if result.stdout:
print(f"Found occurrences of '{base_file_name}':\n{result.stdout}")
else:
print(f"No occurrences found for '{base_file_name}'")
if result.stderr:
print(f"Error: {result.stderr}")
# Define the source directory (containing file names) and search directory
source_dir = "source/educators/migration_wip/images"
search_dir = "source/"
# Call the function
grep_for_filenames(source_dir, search_dir)