Created
July 29, 2021 14:07
-
-
Save Guts/459ba5b9e48eb6457781fd8fbd5460a5 to your computer and use it in GitHub Desktop.
Move folder with all tree files in Python with pathlib and without shutil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python3 | |
import logging | |
from pathlib import Path | |
logging.basicConfig(level=logging.DEBUG) | |
source_dir = Path("/tmp/output_build/") | |
dest_dir = Path("/deployment/") | |
shutil.rmtree(path=dest_dir, ignore_errors=True) | |
dest_dir.mkdir(parents=True, exist_ok=True) | |
for item in source_dir.glob("**/*"): | |
if item.is_dir(): | |
continue | |
# only files | |
final_path = dest_dir / item.relative_to(source_dir) | |
final_path.parent.mkdir(parents=True, exist_ok=True) | |
z = item.replace(final_path.resolve()) | |
logging.info(f"Moved from {item} to {z}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment