Skip to content

Instantly share code, notes, and snippets.

@whitmo
Last active August 29, 2015 14:13
Show Gist options
  • Save whitmo/92cf03b78a6d8ec11d72 to your computer and use it in GitHub Desktop.
Save whitmo/92cf03b78a6d8ec11d72 to your computer and use it in GitHub Desktop.
dir_into_dir
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