Skip to content

Instantly share code, notes, and snippets.

@antfu
Created August 25, 2016 01:04
Show Gist options
  • Save antfu/c5581a1457bc0927305dbf8b9cfda6c0 to your computer and use it in GitHub Desktop.
Save antfu/c5581a1457bc0927305dbf8b9cfda6c0 to your computer and use it in GitHub Desktop.
[Python] Copy directories
def copydir(src,dst):
if not os.path.exists(dst):
os.mkdir(dst)
for f in os.listdir(src):
path = pjoin(src,f)
if os.path.isfile(path):
dst_path = os.path.join(dst,f)
# if the files modify time is the same, do not copy
if not os.path.exists(dst_path) or os.path.getmtime(path) != os.path.getmtime(dst_path):
# use 'copy2' to keep file metadate
shutil.copy2(path,dst_path)
else:
# isdir
copydir(path, pjoin(dst,f), minify)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment