TheSwamp

Code Red => .NET => Topic started by: David Hall on April 13, 2010, 06:06:47 PM

Title: progress bar woes
Post 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...
Code: [Select]
       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 code
Code: [Select]
static 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);
                }
            }
        }
Title: Re: progress bar woes
Post by: T.Willey on April 13, 2010, 06:17:48 PM
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.
Title: Re: progress bar woes
Post by: David Hall on April 13, 2010, 06:25:33 PM
See, I told you I was losing my mind.  Thanks Tim, I knew it was something easy
Title: Re: progress bar woes
Post by: Kerry on April 13, 2010, 06:29:58 PM
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]
Title: Re: progress bar woes
Post by: David Hall on April 13, 2010, 06:47:42 PM
Nope, this one (http://www.theswamp.org/index.php?topic=26486.0)
Title: Re: progress bar woes
Post by: David Hall on April 13, 2010, 06:48:49 PM
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
Title: Re: progress bar woes
Post by: Tuoni on April 14, 2010, 05:12:08 PM
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: