如何检查 FolderBrowserDialog 的内容是否为空?

How can I check the content of the FolderBrowserDialog if is it empty or not?

我在 WPF 项目中使用 FolderBrowserDialog 并且工作正常,我想检查所选文件夹的内容 selectedPath 如果它是空的还是 null 以及存在的文件。

我该怎么做?

try
{
    using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
    {
        System.Windows.Forms.DialogResult result = dialog.ShowDialog();
        FileText.Text = dialog.SelectedPath;
    }
}
catch (Exception exp)
{
    Console.WriteLine("Error : " + exp);
}
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
    System.Windows.Forms.DialogResult result = dialog.ShowDialog();
    if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
    {
        FileText.Text = dialog.SelectedPath;
        var directory = new System.IO.DirectoryInfo(dialog.SelectedPath);

        var files = directory.GetFiles(); // Array with information about files.

        if (files.Length == 0)
            Debug.WriteLine("Empty Folder.");
        else
        {
            var filesTxt = files.Where(f => f.Extension == ".txt").ToArray(); // Array with information about TXT files.
            if (filesTxt.Length == 0)
                Debug.WriteLine("There is no TXT files in the folder.");

        }
    }
}