
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 1.81 KB | hits: 16 | expires: Never
Progress Bar for Copying Files using an Array C#
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
progressBar1.Maximum = pathArray.Length;
progressBar1.Value = 0;
for (int i = 0; i < pathArray.Length; i++)
{
string sourcePath = pathArray[i];
progressBar1.Value++;
if (System.IO.Directory.Exists(sourcePath))
{
System.IO.Directory.CreateDirectory(targetPathProper);
string[] subDirs = System.IO.Directory.GetDirectories(sourcePath,"*",(System.IO.SearchOption.AllDirectories))
progressBar2.Maximum = subDirs.Length;
progressBar2.Value = 0;
foreach (string dirPath in subDirs)
{
progressBar2.Value++;
System.IO.Directory.CreateDirectory(dirPath.Replace(sourcePath,
targetPathProper));
Application.DoEvents();
}
progressBar2.Value = 0;
foreach (string newPath in subDirs)
{
progressBar2.Value++;
System.IO.File.Copy(newPath, newPath.Replace(sourcePath,
targetPathProper), true);
Application.DoEvents();
}
} //end if
} // end for