Repository navigation
Expand file tree
/
Copy pathcopy_def_files.py
More file actions
executable file
·82 lines (67 loc) · 2.44 KB
/
Copy pathcopy_def_files.py
File metadata and controls
executable file
·82 lines (67 loc) · 2.44 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import os
import shutil
import argparse
from pathlib import Path
def copy_def_files(source_dir, target_dir):
"""
Scan directories for .def files and copy them along with their parent directory
to the target location.
Args:
source_dir (str): Source directory path containing container directories
target_dir (str): Target directory path where .def files will be copied
"""
# Convert paths to Path objects for better handling
source_path = Path(source_dir)
target_path = Path(target_dir)
# Create target directory if it doesn't exist
target_path.mkdir(parents=True, exist_ok=True)
# Counter for statistics
dirs_processed = 0
def_files_found = 0
print(f"Scanning {source_dir} for .def files...")
# Iterate through immediate subdirectories
for item in source_path.iterdir():
if item.is_dir():
dirs_processed += 1
def_files = list(item.glob('*.def'))
if def_files:
def_files_found += len(def_files)
dir_name = item.name
new_dir = target_path / dir_name
# Create the directory in the target location
new_dir.mkdir(parents=True, exist_ok=True)
# Copy only .def files
for def_file in def_files:
print(f"Copying {def_file} to {new_dir}")
shutil.copy2(def_file, new_dir)
# Print summary
print("\nSummary:")
print(f"Directories processed: {dirs_processed}")
print(f"Directories with .def files: {def_files_found}")
def main():
# Set up argument parser
parser = argparse.ArgumentParser(
description='Copy .def files from container directories to a target location'
)
parser.add_argument(
'--source_dir',
required=True,
help='Source directory containing container directories'
)
parser.add_argument(
'--destination_dir',
required=True,
help='Destination directory where .def files will be copied'
)
# Parse arguments
args = parser.parse_args()
try:
copy_def_files(args.source_dir, args.destination_dir)
print("\nOperation completed successfully!")
except Exception as e:
print(f"\nAn error occurred: {e}")
return 1
return 0
if __name__ == "__main__":
exit(main())