Getting a list of all the files in a directory

Getting a list of all the files in a directory
With very little C# code you are able to loop through all the files at a given path.
1.  using System;
2.  using System.Collections.Generic;
3.  using System.ComponentModel;
4.  using System.Data;
5.  using System.Drawing;
6.  using System.Text;
7.  using System.Windows.Forms;
8.  // Necessary for the Directory class
9.  using System.IO;
10.  
11. namespace PictureQuality
12. {
13.     public partial class Form1 : Form
14.     {
15.         public Form1()
16.         {
17.             InitializeComponent();
18.         }
19.  
20.         // btnOpen is a simple Button
21.         private void btnOpen_Click(object sender, EventArgs e)
22.         {
23.             // fbdOpen is a FolderBrowserDialog
24.             if (fbdOpen.ShowDialog() == DialogResult.OK)
25.             {
26.                 // Loop through the files in the directory at the selected path
27.                 foreach(string File in Directory.GetFiles(fbdOpen.SelectedPath))
28.                 {
29.                     // Show the complete file path (including file name)
30.                     MessageBox.Show(File);
31.                 }
32.             }
33.         }
34.     }
35. }

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top