folderbrowserdialog selected path
i'm using 'folderBrowserDialog1.SelectedPath' to have a path to chosen folder. How can i see the names of another folders in开发者_如何学运维 folder which is selected?
DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
foreach (DirectoryInfo subDir in dir.GetDirectories())
{
Console.Out.WriteLine(subDir.Name);
}
You're looking for the Directory.GetDirectories
method.
The FolderBrowserDialog component is displayed at run time using the ShowDialog method. Set the RootFolder property to determine the top-most folder and any subfolders that will appear within the tree view of the dialog box. Once the dialog box has been shown, you can use the SelectedPath property to get the path of the folder that was selected
You probably want to use the DirectoryInfo.GetDirectories
method. See here: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.getdirectories(v=vs.71).aspx
The System.IO namespace contains a lot of tools for this. The Directory.GetDirectories
you can use to get al subfolders.
For example:
var folder = folderBrowserDialog1.SelectedPath;
var subFolders = System.IO.Directory.GetDirectories(folder);
精彩评论