Created
May 4, 2012 07:22
-
-
Save artlogic/2592843 to your computer and use it in GitHub Desktop.
Like shutil.copytree, only no need for a containing directory at the source.
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
# copy headless tree | |
rootlen = len(source) + 1 # chop off the leading slash below | |
for root, dirs, files in os.walk(source): | |
diff = root[rootlen:] | |
for f in files: | |
shutil.copy2(os.path.join(root, f), os.path.join(dest, diff)) | |
for d in dirs: | |
try: | |
os.mkdir(os.path.join(dest, diff, d)) | |
except OSError: | |
pass # already exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment