title: Progress bar in console application
body: <p>I'm writing a simple c# console app that uploads files to sftp server. However, the amount of files are large. I would like to display either percentage of files uploaded or just the number of files upload already from the total number of files to be upload.</p>
  
  <p>First, I get all the files and the total number of files.</p>
  
  <pre><code>string[] filePath = Directory.GetFiles(path, "*");
  totalCount = filePath.Length;
  </code></pre>
  
  <p>Then I loop through the file and upload them one by one in foreach loop.</p>
  
  <pre><code>foreach(string file in filePath)
  {
      string FileName = Path.GetFileName(file);
      //copy the files
      oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
      //Console.WriteLine("Uploading file..." + FileName);
      drawTextProgressBar(0, totalCount);
  }
  </code></pre>
  
  <p>In the foreach loop I have a progress bar which I have issues with. It doesn't display properly.</p>
  
  <pre><code>private static void drawTextProgressBar(int progress, int total)
  {
      //draw empty progress bar
      Console.CursorLeft = 0;
      Console.Write("["); //start
      Console.CursorLeft = 32;
      Console.Write("]"); //end
      Console.CursorLeft = 1;
      float onechunk = 30.0f / total;
  
      //draw filled part
      int position = 1;
      for (int i = 0; i &lt; onechunk * progress; i++)
      {
          Console.BackgroundColor = ConsoleColor.Gray;
          Console.CursorLeft = position++;
          Console.Write(" ");
      }
  
      //draw unfilled part
      for (int i = position; i &lt;= 31 ; i++)
      {
          Console.BackgroundColor = ConsoleColor.Green;
          Console.CursorLeft = position++;
          Console.Write(" ");
      }
  
      //draw totals
      Console.CursorLeft = 35;
      Console.BackgroundColor = ConsoleColor.Black;
      Console.Write(progress.ToString() + " of " + total.ToString() + "    "); //blanks at the end remove any excess
  }
  </code></pre>
  
  <p>The output is just [            ] 0 out of 1943</p>
  
  <p>What am I doing wrong here? </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm trying to display the progress bar while I'm loading and exporting XML files. However, it's going through a loop. After it finishes the first round it goes to the second and so on.</p>
  
  <pre><code>string[] xmlFilePath = Directory.GetFiles(xmlFullpath, "*.xml");
  Console.WriteLine("Loading XML files...");
  foreach (string file in xmlFilePath)
  {
       for (int i = 0; i &lt; xmlFilePath.Length; i++)
       {
            //ExportXml(file, styleSheet);
            drawTextProgressBar(i, xmlCount);
            count++;
       }
   }
  </code></pre>
  
  <p>It never leaves the for loop...Any suggestions?</p>