【发布时间】:2012-03-08 00:36:16
【问题描述】:
我有一个 if 语句来检查一个目录是否存在,如果存在,它会将该文件夹复制到指定位置。
整个复制过程是在一组预先确定的文件夹位置上进行的,for 循环遍历该数组并在每个位置复制文件夹及其数据。
目前有 200 个不同的位置可供复制,还有更多位置待添加。
我正在尝试围绕复制这 200 多个文件夹实现一个进度条,但一直遇到错误,我认为我遇到的问题主要是由于数组,我看过的教程(差异很大彼此)只涵盖了基本的文件复制。
任何有关如何使进度条工作的帮助或提示将不胜感激:)
for (int i = 0; i < pathArray.Length; i++)
{
string sourcePath = pathArray[i];
//MISSING CODE
if (System.IO.Directory.Exists(sourcePath))
{
System.IO.Directory.CreateDirectory(targetPathProper);
foreach (string dirPath in System.IO.Directory.GetDirectories(sourcePath,"*",
(System.IO.SearchOption.AllDirectories)))
{
System.IO.Directory.CreateDirectory(dirPath.Replace(sourcePath,
targetPathProper));
}
foreach (string newPath in System.IO.Directory.GetFiles(sourcePath, "*",
(System.IO.SearchOption.AllDirectories)))
{
System.IO.File.Copy(newPath, newPath.Replace(sourcePath,
targetPathProper), true);
}
} //end if
} // end for
【问题讨论】:
-
什么样的错误?请更具体。您的问题是否与错误有关,或者它如何实现进度条?
-
下载vXCopy (C# 2.0) 的源码,学习实现。更好的是,按原样使用它。 vxcopy.codeplex.com
-
我的问题是如何实现它对不起:P 目前我只是在阅读 backgroundWorker :P
标签: c# arrays winforms progress-bar