Skip to content

Instantly share code, notes, and snippets.

@Guts
Created July 29, 2021 14:07
Show Gist options
  • Save Guts/459ba5b9e48eb6457781fd8fbd5460a5 to your computer and use it in GitHub Desktop.
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
#! 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