Compressing directory using shutil.make_archive() while preserving directory structure

Using the terms in the documentation, you have specified a root_dir, but not a base_dir. Try specifying the base_dir like so: shutil.make_archive(‘/home/code/test_dicoms’, ‘zip’, ‘/home/code/’, ‘test_dicoms’) To answer your second question, it depends upon the version of Python you are using. Starting from Python 3.4, ZIP64 extensions will be availble by default. Prior to Python 3.4, … Read more

shutil.rmtree fails on Windows with ‘Access is denied’ [duplicate]

Check this question out: What user do python scripts run as in windows? Apparently the answer is to change the file/folder to not be read-only and then remove it. Here’s onerror() handler from pathutils.py mentioned by @Sridhar Ratnakumar in comments: def onerror(func, path, exc_info): “”” Error handler for “shutil.rmtree“. If the error is due to … Read more

Copy directory contents into a directory with python [duplicate]

I found this code working which is part of the standard library: from distutils.dir_util import copy_tree # copy subdirectory example from_directory = “/a/b/c” to_directory = “/x/y/z” copy_tree(from_directory, to_directory) Reference: Python 2: https://docs.python.org/2/distutils/apiref.html#distutils.dir_util.copy_tree Python 3: https://docs.python.org/3/distutils/apiref.html#distutils.dir_util.copy_tree