-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathcopy_dir.py
More file actions
40 lines (31 loc) · 1.01 KB
/
copy_dir.py
File metadata and controls
40 lines (31 loc) · 1.01 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
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
import logging
import shutil
import sys
from pathlib import Path
def copy_files(source: Path, destination: Path) -> None:
if destination.exists():
shutil.rmtree(destination)
destination.mkdir()
for file in source.iterdir():
if file.is_file():
shutil.copy(file, destination / file.name)
else:
copy_files(file, destination / file.name)
if __name__ == "__main__":
if len(sys.argv) != 3: # noqa
logging.error(
"Script used incorrectly!\nUsage: python copy_dir.py <source_dir> <destination>"
)
sys.exit(1)
root_dir = Path(__file__).parent.parent.parent
src = Path(root_dir / sys.argv[1])
dest = Path(root_dir / sys.argv[2])
print(f"Copying files from '{sys.argv[1]}' to '{sys.argv[2]}'...") # noqa: T201
if not src.exists():
logging.error("Source directory %s does not exist", src)
sys.exit(1)
copy_files(src, dest)