used for loop where p is string for directories here is the full code
// recursive method to load all folders and files into tree
private void GetFolders( string path, TreeNodeCollection nodes )
{
// add nodes for all directories (folders)
string[] dirs = Directory.GetDirectories( path );
foreach( string p in dirs )
{
string dp = p.Substring( path.Length );
nodes.Add(Node("",p.Substring( path.Length + 1), "folder" ) );
}
// add nodes for all files in this directory (folder)
string\[\] files = Directory.GetFiles( path, "\*.\*" );
foreach( string p in files )
{
nodes.Add( Node( p, p.Substring( path.Length ), "file" ) );
}
// add all subdirectories for each directory (recursive)
for( int i = 0; i < nodes.Count; i++ )
{
if ( nodes\[ i \].Type == "folder" )
{
GetFolders( dirs\[ i \] + "\\\\", nodes\[i \].Nodes );
}
}
}