Python - 用于复制和移动文件的进度条

时间:2016-02-19 12:44:50

标签: python python-2.7 progress-bar

我创建了一个程序,可以将文件复制并移动到不同的方向。我认为在整个过程中添加进度条会很有趣。 我应该如何接近它?

我的脚本做了一些思考:

将没有.mdi文件的文件排序到文件夹"缺少mdi"

我使用了distutils.dir_util.copy_tree,因为shutil.copytree存在访问问题

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 )

1 个答案:

答案 0 :(得分:1)

尝试使用包进度条

main :: IO ()
main =
  let window = InWindow "Tic Tac Toe" (300, 300) (10, 10)
      size   = 100.0
  in play window yellow 1 emptyBoard (drawBoard size) (handleKeys size) (flip const)