目录和文件复制在另一个位置 [英] Directory and Files Coying on another location

查看:105
本文介绍了目录和文件复制在另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建具有进度条和文件大小百分比的目录和文件压缩Winform应用程序?

How to create Directory and Files Coying winform application having progress bar with percentage of file size?

推荐答案

您从复制作业的根文件夹开始,得到该文件夹中每个文件的文件信息,将所有文件大小加在一起,并递归遍历根目录下的整个子文件夹结构,从而继续库存所有文件以获取大小信息.

然后,您回到根文件夹并开始一个接一个地复制文件,在目标的根目录中创建所有文件夹.同样,您在源文件夹中的每个文件夹中递归执行相同的操作.

跟踪已复制的字节数,即可轻松完成进度条的百分比.

哦!您需要将文件清单和复制代码放在单独的线程中,以便可以使UI线程可用于处理屏幕更新和用户单击,例如取消"按钮.
You start at the root folder of your copy job, getting the file information for every file in that folder, adding up all the file sizes, and recursively traversing the entire subfolder structure under the root, continuing to inventory all the file for size information.

Then, you go back to the root folder and start copying files, one by one, creating all the folders in the root on the target. Again, you recursively do this same thing in each and every folder in your source folder.

Keep track of the number of bytes you''ve copied and you can easily get the percentage complete for your progress bar.

Oh! You''ll want to put the file inventory and copy code in a seperate thread so you can keep the UI thread available to handle screen updates and user clicks, like the Cancel button.


这篇关于目录和文件复制在另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆