35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import os
|
|
import shutil
|
|
|
|
SRC_DIR = "src"
|
|
HOME_DIR = os.path.expanduser("~")
|
|
|
|
def ask_override(path):
|
|
resp = input(f"'{path}' already exists. Override? (Y/N): ").strip().lower()
|
|
return resp == 'y'
|
|
|
|
def copy_with_structure(src_root, dst_root, override_all=False):
|
|
for root, dirs, files in os.walk(src_root):
|
|
rel_path = os.path.relpath(root, src_root)
|
|
target_dir = os.path.join(dst_root, rel_path)
|
|
|
|
os.makedirs(target_dir, exist_ok=True)
|
|
|
|
for file in files:
|
|
src_file = os.path.join(root, file)
|
|
dst_file = os.path.join(target_dir, file)
|
|
|
|
if os.path.exists(dst_file):
|
|
if not override_all and not ask_override(dst_file):
|
|
continue
|
|
|
|
shutil.copy2(src_file, dst_file)
|
|
print(f"Copied: {src_file} -> {dst_file}")
|
|
|
|
def main():
|
|
override_all = input('Override all existing files? (Y/N): ').strip().lower() == 'y'
|
|
copy_with_structure(SRC_DIR, HOME_DIR, override_all)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|