Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //obtain the directory we’re wanting to search for files…
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
- folderToSearch = folderBrowserDialog1.SelectedPath; //make folderToSearch a form-level public variable
- }
- //if we want only top-level files (those not in subfolders of folderToSearch), then…
- DirectoryInfo di = new DirectoryInfo(folderToSearch);
- FileInfo[] fi = di.GetFiles(“*.*”, SearchOption.TopDirectoryOnly);
- //if we want to include subdirectories in our search:
- DirectoryInfo di = new DirectoryInfo(folderToSearch);
- FileInfo[] fi = di.GetFiles(“*.*”, SearchOption.AllDirectories);
- //now the fi array instance contains full paths of all found files (let’s put filenames in a listbox):
- lstFiles.Items.Clear();
- foreach (FileInfo filinf in fi) {
- lstFiles.Items.Add(Path.GetFileName(filinf.FullName));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement