OK, I must be losing my mind. Using code from Kerry's post on file recursion, I am trying to make a progess bar to let the user know it didn't hang up. My folder I'm starting with has 31 drawings in it. The code runs, and then crashes when the count goes to 32... private void btnFindDups_Click(object sender, EventArgs e)
{
string pathCFiles = txtCompletedFiles.Text;
string[] arrCompletedDrawings = Directory.GetFiles(pathCFiles, "*.dwg");
string dupeFile = pathCFiles + "\\" + "Dupes.txt";
string pathLockedFiles = txtSearchFolder.Text;
progressBar1.Visible = true;
progressBar1.Minimum = 1;
progressBar1.Maximum = arrCompletedDrawings.Count();
progressBar1.Value = 1;
foreach (string dwg in arrCompletedDrawings)
{
string filedwg = dwg.Substring(dwg.LastIndexOf("\\") + 1);
LoadDirFiles(pathLockedFiles, true, filedwg, dupeFile);
progressBar1.Value += 1;
}
MessageBox.Show("Completed Search for Duplicates");
}
and the search codestatic void WriteDups(string dupDWG, string dupFile)
{
StreamWriter sw = new StreamWriter(dupFile, true);
sw.WriteLine(dupDWG);
sw.Close();
}
private void LoadDirFiles(string Dir, bool CheckSubs, string dwgTF, string dupFile)
{
string[] fls = Directory.GetFiles(Dir);
foreach (string fl in fls)
{
string filedwg = fl.Substring(fl.LastIndexOf("\\") + 1);
if (dwgTF == filedwg)
{
WriteDups(fl, dupFile);
}
}
if (CheckSubs)
{
string[] dirs = Directory.GetDirectories(Dir);
foreach (string d in dirs)
{
LoadDirFiles(d, CheckSubs, dwgTF, dupFile);
}
}
}