Python how to link progress bar to distutils.dir_util.copy_tree

I made a small application, basically at some point I call distutils.dir_util.copy_tree which copies the file to the destination. Can anyone help me link a basic progress bar like:

[======]50%

      

to the copying process ... unfortunately, I can't guess that I'm going to take a long time to make a copy of the folder tree, as it will be different from time to time. Thanks in advance to everyone who answers me.

+3


source to share


3 answers


distutils.dir_util.copy_tree()

does not provide a callback that you can use to do this. You will need to use os.walk()

to enumerate filesystem objects and then use shutil.copy[2]()

to copy real objects.



+3


source


Corey Glodberg wrote about a simple lib for doing ascii progress step in command line applications, you might be wondering:



http://coreygoldberg.blogspot.com.es/2010/01/python-command-line-progress-bar-with.html

0


source


As explained in the Python doc, you can provide a callback for shutil.copytree.

from shutil import copytree

def _countFiles(path, names):
    #do someting with "path" and "names"
    return []   # nothing will be ignored

copytree(source, destination, ignore=_countFiles)

      

I haven't written any code to make progress, but you get the idea:

  • count files in your directory (and subdirectories)
  • in "_countFiles", increase the number of processed files
  • progress = nb_processed_files * 100 / nb_total_files

Hello

0


source







All Articles