I create a program which copy and move file to different direction. I was thinking that it would be interesting to add a progress bar to a whole process. How i should approach to it?
My script do a few more thinks:
Sort files with no .mdi file to a folder "missing mdi"
I used distutils.dir_util.copy_tree because shutil.copytree had problem with acces
src = raw_input("Enter source disk location: ")
src = os.path.abspath(src)
dst = raw_input("Enter first destination : ")
dst = os.path.abspath(dst)
dest = raw_input("Enter second destination : ")
dest = os.path.abspath(dest)
for dir, dirs, files in os.walk(src):
if any(f.endswith('.mdi') for f in files):
dirs[:] = [] # do not recurse into subdirectories
continue # ignore this directory
# do something with the files here, there are no .txt files.
files = [os.path.join(dir, f) for f in files]
print "files -->", files
for list in files:
print "list --->", list
#---------parameters-------------------#
part1 = os.path.dirname(list)
print "part1" ,part1
part2 = os.path.dirname(os.path.dirname(part1))
print "part2" ,part2
part3 = os.path.split(part1)[1]
print "part 3 ->",part3
path_miss1 = os.path.join(dst, "missing_mdi")
print "path_miss1", path_miss1
#---------first location-------------------#
path_miss = os.path.join(path_miss1, part3)
print "path_miss", path_miss
#---------second location-------------------#
path_missing = os.path.join(dest, "missing_mdi")
print "path_missing", path_missing
try:
#---------first location-------------------#
if not os.path.exists(path_miss):
os.makedirs(path_miss)
else:
pass
if os.path.exists(path_miss):
distutils.dir_util.copy_tree(part1,path_miss)
else:
print "missing_file"
if(get_size(path_miss)) == 0:
os.rmdir(path_miss)
else:
pass
#---------second location-------------------#
if not os.path.exists(path_missing):
os.makedirs(path_missing)
else:
pass
if os.path.exists(path_missing):
shutil.move(part1,path_missing)
else:
print "missing_file"
if(get_size(path_missing)) == 0:
os.rmdir(path_missing)
else:
pass
except Exception, l:
print "l --->",str ( l )
try to use package progressbar
from progressbar import ProgressBar, Percentage, Bar, ETA
from time import sleep
progress, progress_maxval = 0, 10
pbar = ProgressBar(widgets=['Progress ', Percentage(), Bar(), ' ', ETA(), ],
maxval=progress_maxval).start()
for i in xrange(progress_maxval):
progress += 1
sleep(1)
pbar.update(progress)
pbar.finish()