Created
June 7, 2019 03:10
-
-
Save sodre/69ade4a914338148424dc21cf30785fd to your computer and use it in GitHub Desktop.
Simple python code for overlaying a source directory on top of another (existing) dir.
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
# A Python function for overlaying a source directory on top of a destination dir | |
import os | |
import shutil | |
def overlay_dir(prefix, src, dest): | |
abs_src = os.path.abspath(src) | |
abs_dest = os.path.join(prefix, dest) | |
for root, dirs, files in os.walk(abs_src): | |
dest_root=root.replace(abs_src, abs_dest) | |
if not os.path.exists(dest_root): | |
os.mkdir(dest_root) | |
for f in files: | |
src_file=os.path.join(root, f) | |
dest_file=os.path.join(dest_root, f) | |
shutil.copy2(src_file, dest_file) | |
if __name__ == "__main__": | |
prefix = "/tmp" | |
user_input = ("..", "tmp") | |
overlay_dir(prefix, *user_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment