-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (26 loc) · 1.15 KB
/
utils.py
File metadata and controls
31 lines (26 loc) · 1.15 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
import os
def copy_directory_without_comments(source_dir: str, destination_dir: str):
# Create the destination directory if it doesn't exist
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)
# Walk through the source directory
for root, dirs, files in os.walk(source_dir):
# Create corresponding subdirectories in the destination
for dir_name in dirs:
source_subdir = os.path.join(root, dir_name)
dest_subdir = os.path.join(
destination_dir, os.path.relpath(source_subdir, source_dir)
)
if not os.path.exists(dest_subdir):
os.makedirs(dest_subdir)
# Process files
for file_name in files:
source_file = os.path.join(root, file_name)
dest_file = os.path.join(
destination_dir, os.path.relpath(source_file, source_dir)
)
# Copy and process the file
with open(source_file, "r") as src, open(dest_file, "w") as dst:
for line in src:
if not line.lstrip().startswith("//"):
dst.write(line)