Hi
As I understand you wanted to get the name of directories in side a
directory.
The following code illustrates the navigation of all files inside a
directory.. including directories.
class Program
{
static void Main(string[] args)
{
string path =
Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments);
DirectoryInfo rootDirInfo = new DirectoryInfo(path);
DisplayFilesOfDir(rootDirInfo);
Console.ReadLine();
}
public static void DisplayFilesOfDir(DirectoryInfo di)
{
DirectoryInfo[] dirInfo = di.GetDirectories();
foreach (DirectoryInfo dirInfoindex in dirInfo)
{
Console.WriteLine(dirInfoindex.Name);
DisplayFilesOfDir(dirInfoindex);
}
FileInfo[] fileInfos = di.GetFiles();
foreach (FileInfo fi in fileInfos)
Console.WriteLine(fi.Name);
}
}
Hope this is helpful to you.
Thanks
-Srinivas.
Ronald S. Cook wrote:
I'm wanting to scan all folders and files under a specified path (e.g.
C:\Files). I know using System.IO I can use Directory.GetFiles to get a
list of files under a folder, but how do I get the name of the folder?
Is there any sample code out there that can kickstart me?
Thanks,
Ron