title: How do I get the files names from FileInfo[]?
body: <p>I have this code:</p>
  <pre><code>_fi = new DirectoryInfo (subDirectoryName).GetFiles(&quot;*.bmp&quot;);
  label15.Text = _fi.Length.ToString();
  for (int i = 0; i &lt; myNumbers.Count; i++)
  {
      if (myNumbers[i] &gt;= max_min_threshold)
      {
          FileName = i.ToString(&quot;D6&quot;) + &quot;.bmp&quot;;
          if (File.Exists(subDirectoryName + &quot;\\&quot; + FileName))
             ...
      }
  }
  </code></pre>
  <p>Now _fi contain 2255 indexes; in each index there is a file name for example in index[0] I see: {000001.bmp}<br />
  In index[1] {000002.bmp}</p>
  <p>Then I'm running over myNumbers which contain 2256 indexes in each one a number. For example in index[0] there is 225000 in index[1] there is 223000 and so on.</p>
  <p>What I want to do is using this loop or some other way and each iteration to get the file name from the _fi variable into FileName variable.</p>
  <p>So in the first variable FileName will be 000001.bmp in the second iteration FileName will be 000002.bmp and so on.</p>
  <p>The problem is FileName now in the first iteration will be 000000.bmp which does not exist in the hard disk. I see it in _fi the first file is 000001.bmp</p>
  <p>So how can I make it work out?</p>
  <p>EDITED:</p>
  <p>Tried to do this:</p>
  <pre><code>if (i == _fi.Length)
                              {
                                  break;
                              }
                              FileName = (i + 1).ToString(&quot;D6&quot;) + &quot;.bmp&quot;;
  </code></pre>
  <p>The problem is that after the break its going to this part:</p>
  <pre><code>button5.Enabled = true;
                          myTrackPanelss1.trackBar1.Maximum = counter;
                          myTrackPanelss1.trackBar1.Value = 0;
                          setpicture(0);
  </code></pre>
  <p>Now setpicture(0); will show in pictureBox1 the frame/image number 1 which is file: 000001.bmp
  This is the setpicture function:</p>
  <pre><code>private void setpicture(int indx)
          {
              if (_fi == null)
              {
                  pictureBox1.Image = Lightnings_Extractor.Properties.Resources.Weather_Michmoret;
                  button5.Enabled = false;
                  label5.Visible = true;
              }
              else
              {
                  if (indx &gt;= 0 &amp;&amp; indx &lt;= myTrackPanelss1.trackBar1.Maximum &amp;&amp; _fi.Length &gt; indx)
                  {
                      try
                      {
                          label19.ForeColor = Color.Red;
                          fileToolStripMenuItem.Enabled = true;
                          label19.Visible = false;
                          label20.Visible = false;
                          label14.Visible = true;
                          label15.Visible = true;
                          label8.Visible = true;
                          label9.Visible = true;
                          myTrackPanelss1.trackBar1.Enabled = true;
                          using (FileStream fs = new FileStream(_fi[indx].FullName, FileMode.Open))
                          {
                              this.label8.Visible = true;
                              this.label9.Visible = true;
                              this.label9.Text = _fi[indx].Name;
                              Image img = null;
                              Bitmap bmp = null;
                              Image imgOLd = null;
  
                              try
                              {
                                    
                                  img = Image.FromStream(fs);
                                  bmp = new Bitmap(img);
  
                                  imgOLd = this.pictureBox1.Image;
                                  this.pictureBox1.Image = bmp;
                                  if (imgOLd != null)
                                      imgOLd.Dispose();
  
                                  img.Dispose();
                                  img = null;
                              }
                              catch
                              {
                                  if (img != null)
                                      img.Dispose();
                                  if (bmp != null)
                                      bmp.Dispose();
                                  if (imgOLd != null)
                                      imgOLd.Dispose();
                              }
                          }
                      }
                      catch
                      {
                          button1.Enabled = false;
                          label1.Visible = false;
                          label2.Visible = false;
                          label3.Visible = false;
                          label4.Visible = false;
                          label11.Visible = false;
                          label12.Visible = false;
                          checkBox2.Enabled = false;
                          label19.Visible = true;
                          label19.ForeColor = Color.Green;
                          label19.Text = &quot;The Selected Directory Is Access Denied&quot;;
                          label20.Visible = true;
                          label20.ForeColor = Color.Green;
                          label20.Text = &quot;Please Set A Different Directory&quot;;
                          fileToolStripMenuItem.Enabled = false;
                          label14.Visible = false;
                          label15.Visible = false;
                          label8.Visible = false;
                          label9.Visible = false;
                          myTrackPanelss1.trackBar1.Enabled = false;
                          timer2.Stop();
                          return;
                      }
                  }
                  else
                  {
                      Image imgOLd = this.pictureBox1.Image;
                      //this.pictureBox1.Image = null;
  
                      if (imgOLd != null)
                      {
                          imgOLd.Dispose();
                          imgOLd = null;
                      }
                      
                      Application.DoEvents();
                  }
              }
          }
  </code></pre>
  <p>On the line:</p>
  <pre><code>using (FileStream fs = new FileStream(_fi[indx].FullName, FileMode.Open))
  </code></pre>
  <p>I'm getting exception now which was not before I did the break; if i == _fi.Length but after I did it I'm getting exception on this line its moving to the catch area and throw me:</p>
  <p>The process cannot access the file 'D:\New folder (7)\MVI_3041.MOV_Automatic\000001.bmp' because it is being used by another process.</p>
  <pre><code>System.IO.IOException was caught
    Message=The process cannot access the file 'D:\New folder (7)\MVI_3041.MOV_Automatic\000001.bmp' because it is being used by another process.
    Source=mscorlib
    StackTrace:
         at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
         at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
         at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
         at System.IO.FileStream..ctor(String path, FileMode mode)
         at Extracting_Frames.Form1.setpicture(Int32 indx) in D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\Form1.cs:line 508
    InnerException: 
  </code></pre>
  <p>I'm not sure why now I'm getting this exception which wasn't before.</p>