Get a list of files from a folder based on the result of a FolderBrowserDialog : Dialog « GUI Windows Form « C# / C Sharp






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

1.A dialog by user defined property
2.Color Fill dialog
3.Color Scroll Dialog Box
4.Italic User Message Dialog: your own dialog
5.Use DialogResult property in Form
6.Define your own dialog box and get user inputDefine your own dialog box and get user input
7.Microsoft.Win32.OpenFileDialog/SaveFileDialog