How to Copy Files Fast

The fastest version w/o overoptimizing the code I’ve got with the following code: class CTError(Exception): def __init__(self, errors): self.errors = errors try: O_BINARY = os.O_BINARY except: O_BINARY = 0 READ_FLAGS = os.O_RDONLY | O_BINARY WRITE_FLAGS = os.O_WRONLY | os.O_CREAT | os.O_TRUNC | O_BINARY BUFFER_SIZE = 128*1024 def copyfile(src, dst): try: fin = os.open(src, READ_FLAGS) stat … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)