Skip to content

Instantly share code, notes, and snippets.

@artlogic
Created May 4, 2012 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlogic/2592843 to your computer and use it in GitHub Desktop.
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.
# 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