It is very easy to delve into the files and folders on your computer in C#. The DirectoryInfo class contains a wealth of methods for reading, creating and modifying files and folders.
Here is an example created in Grasshopper showing how we can use the DirectoryInfo class to get a list of subfolders contained within a folder.
Source code
This code takes in a folder path as a string, and returns a list of folder names contained within that folder.
The code is formatted for the C# component in Grasshopper but can be modified to suit any C# application.
private void RunScript(string dir, ref object dirs) { System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(dir); System.IO.DirectoryInfo[] dirInfos = dirInfo.GetDirectories("*.*"); List<string> dirNames = new List<string>(); foreach(System.IO.DirectoryInfo d in dirInfos) { dirNames.Add(d.Name); } dirs = dirNames; }