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.
source to share
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
source to share
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
source to share