This is a simple question and I am sure you C# Pros know it.
If you want to grab the contents of a directory on a hard drive (local or otherwise) in a C Sharp program, how do you go about it?
This is a simple question and I am sure you C# Pros know it.
If you want to grab the contents of a directory on a hard drive (local or otherwise) in a C Sharp program, how do you go about it?
If you mean get a directory then it is very simple. The following code will give you a list of all the directories in a given directory and then list all the files in the directory:
string dir = @"C:\Users\Joe\Music";
DirectoryInfo dirInfo = new DirectoryInfo(dir);
FileInfo[] files = dirInfo.GetFiles();
DirectoryInfo[] directories = dirInfo.GetDirectories();
foreach (DirectoryInfo directory in directories)
Console.WriteLine(directory.Name);
foreach (FileInfo file in files)
Console.WriteLine (file.Name);