Retrieving the contents of a directory in C# is very easy, and the code is included below.
DirectoryInfo directory = new DirectoryInfo("C:/some/directory");
FileInfo[] files = directory.GetFiles();
foreach (FileInfo onefile in files){
Console.WriteLine(onefile.Name);
}
The DirectoryInfo object points at a directory on the system. From here, the program has access to create and delete other directories, list directories and files, and view last accessed time information. GetFiles() returns an array of FileInfo objects, and from there, the program has access to information about each file in the directory.Original file listing method found here - http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=356
No comments:
Post a Comment