Last active
August 29, 2015 14:13
-
-
Save whitmo/92cf03b78a6d8ec11d72 to your computer and use it in GitHub Desktop.
dir_into_dir
This file contains hidden or 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
def copy_into(directory, target_dir): | |
with directory.relpath(): | |
for pth in path('./').walk(): | |
tgt = target_dir.joinpath(*pth.splitpath()) | |
if pth.isdir(): | |
tgt.makedirs_p() | |
continue | |
if pth.islink(): | |
link = pth.realpath().relpath() | |
new_tgt = target_dir.joinpath(*link.splitpath()) | |
if not new_tgt.exists(): | |
link.copyfile(new_tgt) | |
with tgt.parent: | |
new_tgt = new_tgt.relpath() | |
new_tgt.symlink(tgt.relpath()) | |
continue | |
else: | |
pth.copyfile(tgt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment