Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.81 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Progress Bar for Copying Files using an Array C#
  2. for (int i = 0; i < pathArray.Length; i++)
  3. {
  4.  
  5.    string sourcePath = pathArray[i];
  6.  
  7.    //MISSING CODE
  8.  
  9.    if (System.IO.Directory.Exists(sourcePath))
  10.    {                  
  11.  
  12.       System.IO.Directory.CreateDirectory(targetPathProper);
  13.  
  14.       foreach (string dirPath in System.IO.Directory.GetDirectories(sourcePath,"*",
  15.           (System.IO.SearchOption.AllDirectories)))
  16.       {
  17.          System.IO.Directory.CreateDirectory(dirPath.Replace(sourcePath,
  18.                 targetPathProper));
  19.       }
  20.  
  21.       foreach (string newPath in System.IO.Directory.GetFiles(sourcePath, "*",
  22.           (System.IO.SearchOption.AllDirectories)))
  23.       {
  24.          System.IO.File.Copy(newPath, newPath.Replace(sourcePath,
  25.              targetPathProper), true);
  26.       }
  27.  
  28.    } //end if
  29. } // end for
  30.        
  31. progressBar1.Maximum = pathArray.Length;
  32. progressBar1.Value = 0;
  33. for (int i = 0; i < pathArray.Length; i++)
  34. {
  35.  
  36.    string sourcePath = pathArray[i];
  37.  
  38.    progressBar1.Value++;
  39.  
  40.    if (System.IO.Directory.Exists(sourcePath))
  41.    {                  
  42.  
  43.       System.IO.Directory.CreateDirectory(targetPathProper);
  44.       string[] subDirs = System.IO.Directory.GetDirectories(sourcePath,"*",(System.IO.SearchOption.AllDirectories))
  45.       progressBar2.Maximum = subDirs.Length;
  46.       progressBar2.Value = 0;
  47.       foreach (string dirPath in subDirs)
  48.       {
  49.          progressBar2.Value++;
  50.          System.IO.Directory.CreateDirectory(dirPath.Replace(sourcePath,
  51.             targetPathProper));
  52.          Application.DoEvents();
  53.       }
  54.  
  55.       progressBar2.Value = 0;
  56.       foreach (string newPath in subDirs)
  57.       {
  58.          progressBar2.Value++;
  59.          System.IO.File.Copy(newPath, newPath.Replace(sourcePath,
  60.              targetPathProper), true);
  61.          Application.DoEvents();
  62.       }
  63.  
  64.    } //end if
  65. } // end for