Get a list of files from a folder based on the result of a FolderBrowserDialog
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text.RegularExpressions;
public class Utils
{
public static List<string> GetFilesFromFolder(bool bSubDirs)
{
FolderBrowserDialog dlgFolder = new FolderBrowserDialog();
dlgFolder.SelectedPath = "";
if (dlgFolder.ShowDialog() == DialogResult.Cancel)
return new List<string>();
string sDir = dlgFolder.SelectedPath;
string[] sFileList;
if (bSubDirs)
sFileList = Directory.GetFiles(sDir, "*.*", SearchOption.AllDirectories);
else
sFileList = Directory.GetFiles(sDir);
return new List<string>(sFileList);
}
}
Related examples in the same category