I am trying to copy over a terabyte of data from one network location to another using the python script below.
import shutil
import os
import logging
# logging copy data
def _logpath(path, names):
logging.info('Working in %s' % path)
return [] # nothing will be ignored
# path to source directory
src_dir = r'\\networkDrive1\allFolders'
# path to destination directory
dest_dir = r'\\networkDrive2\folder1\folder2\destinationFolder'
# getting all the files in the source directory
files = os.listdir(src_dir)
# copying files
shutil.copytree(src_dir, dest_dir, ignore=_logpath)
I am wondering if the code is sufficient to copy the complete directory, including subfolders and I'd like to monitor the output so I know what files are being copied at a given time.
I found a solution that works for me
import shutil
import os
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
# Logging copy progress
def _logpath(path, names):
logging.info('Copying files from %s' % path)
logging.info('Files and directories to be copied: %s' % names)
return [] # nothing will be ignored
# path to source directory
src_dir = r'\\networkDrive1\allFolders'
# path to destination directory
dest_dir = r'\\networkDrive2\folder1\folder2\destinationFolder'
# getting all the files in the source directory
files = os.listdir(src_dir)
# copying files
shutil.copytree(src_dir, dest_dir, ignore=_logpath)