TheSwamp
Code Red => .NET => Topic started by: David Hall on April 13, 2010, 06:06:47 PM
-
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);
}
}
}
-
Just looking at the code. You say the max is 31, and the min is 1. Once you finish the first drawing, you progress meter is set to 2. So when you finish all the drawings, you meter is set to 32 ( more than your max ). Either start at 0, or add one to the max count.
-
See, I told you I was losing my mind. Thanks Tim, I knew it was something easy
-
Hi David,
were you referring to this one ? http://www.theswamp.org/index.php?topic=29992.msg355647#msg355647
I should start keeping better notes on my research 'cause my memory is not what it used to be :(
I think Tim is correct
Just for fun, what happens if you try this
progressBar1.Maximum = (5 + arrCompletedDrawings.Count() );
edit: [oops] late to the party again [/oops]
-
Nope, this one (http://www.theswamp.org/index.php?topic=26486.0)
-
Kerry, I had to study yours and TT's code for 2 days to figure out what TT was saying. I still don't understand why he said your was not recursive
-
I still don't understand why he said your was not recursive
Because a recursive method is one which calls itself on its results. Kerry's is basically working its way through a stack until there's nothing left to push/pop.
But both of them hurt my head :lol: