Created
August 25, 2016 01:04
-
-
Save antfu/c5581a1457bc0927305dbf8b9cfda6c0 to your computer and use it in GitHub Desktop.
[Python] Copy directories
This file contains 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 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