I kinda have a problem. I’m trying to make a form that copies stuff from point A to B with a statusbar. Now the copying works fine but the statusbar just isn’t doing anything..
Anyone got any clue?
public partial class Form4A : Form
{
public Form4A()
{
InitializeComponent();
OtherSettings();
BackgroundWorker.RunWorkerAsync(); // Starts wow copying
}
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
string SourcePath = RegistryRead.ReadOriginalPath();
string DestinationPath = RegistryRead.ReadNewPath();
if (!Directory.Exists(SourcePath))
{
for (int i = 1; i <= 100; i++)
{
//Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(SourcePath, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));
//Copy all the files
foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath));
BackgroundWorker.ReportProgress(i);
}
}
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
}
You say:
if (!Directory.Exists(DestinationPath)). This means that the loop will never be executed, if the desination path exists. Make sure you delete the DestinationPath before you test your code!EDIT: