I have an if statement that checks if a directory exists and if it does it copies that folder to the specified location.
The entire copy process is on an array of pre-determined folder locations, for loop goes through the array and copies the folder and its data at each location.
At the moment there are 200 different locations to copy with more still to be added.
I am trying to implement a progress bar around the copying of these 200+ folders but keep running in to errors, I think the issue I am having is mainly due to the array, the tutorials I’ve seen (which differed greatly from one another) covered just basic file copying.
Any help or tips on how to get a progress bar working would be much appreciated 🙂
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
You say you get an error, what error are you getting?
As for your progress bar, you can simply increment at each base directory in the array. No real need to increment for every file. Or if there is a need to indicate progress on every file you can have two progress bars.