有没有办法追踪机器人的进展

2024-05-15 16:55:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我和tkinter做了一个进度条。我正在尝试让进度条跟踪复制进度。有没有一种方法可以查看robocopy的进度并将其用于进度条?在

我知道有某种解决方案,通过计算源目录的大小,然后检查目标目录的大小。它确实有用,但我不能检查是否有任何被robocopy跳过的内容,然后进度条将永远显示。在

我把这个代码用于机器人游戏:

subprocess.call(["robocopy", os.path.dirname(file_path), new_destination, filename[0], "/V", "/ETA", "/W:3", "/R:3",
                          "/TEE", "/LOG+:" +
                          new_destination + "copy.log"])

如果可能的话,我想用robocopy输出的进度更新进度条,如果不可能的话,可以用一种方法来检查robocopy是否完成。在

提前谢谢!在


Tags: path方法代码进度条游戏内容newtkinter
1条回答
网友
1楼 · 发布于 2024-05-15 16:55:41

首先,当我按下一个按钮并选择了要复制的文件/目录时,我会检查它们的大小。我保存它并将进度条的最大值设置为总大小。然后执行start_calc方法。在

for item in self.file_and_directory_list:
            folder = ""
            my_file = ""
            if os.path.isdir(item):
                folder = item
            else:
                my_file = item

            if folder != "":
                print("folder")
                for (path, dirs, files) in os.walk(folder):
                    for file in files:
                        filename = os.path.join(path, file)
                        folder_size += os.path.getsize(filename)
            else:
                folder_size += os.path.getsize(item)

        if os.path.exists(new_destination):
            for (path, dirs, files) in os.walk(new_destination):
                for file in files:
                    filename = os.path.join(path, file)
                    folder_size += os.path.getsize(filename)

        processing_bar_copy_files["maximum"] = folder_size

        processing_bar_copy_files["value"] = 0

        threading.Thread(target=self.start_calc, args=(folder_size, new_destination)).start()   

start_calc方法,在这里我计算目标目录的大小,并检查它是否比源目录小。如果该值较小,则进度条的值设置为目标目录的大小:

^{pr2}$

如果文件复制完成,进度条将被删除并停止,按钮将放回原处。在

相关问题 更多 >