TsvGis TsvGis - 4 years ago 164
Python Question

Python shutil.copytree() is there away to track the status of the copying

I have a lot of raster files (600+) in directories that I need copy into a new location (including their directory structure). Is there a way to track the status of the copying using shutil.copytree()? Normally with files I would use the code below, but not sure how to do the same with shutil.copytree():

for currentFolder, subFolder, fileNames in os.walk(sourceFolder):
for i in fileNames:
if i.endswith(".img"):
print "copying {}".format(i)
shutil.copy(os.path.join(currentFolder,i), outPutFolder)

Answer Source

Yes, something like this is possible by taking advantage of the function name passed in for 'ignore' parameter. In fact something like this is given in the example section of python docs: https://docs.python.org/2/library/shutil.html#copytree-example

Example pasted below as well:

from shutil import copytree
import logging

def _logpath(path, names):
    logging.info('Working in %s' % path)
    return []   # nothing will be ignored

copytree(source, destination, ignore=_logpath)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download