Home > C# > How to access all files in a directory programmatically?

How to access all files in a directory programmatically?

This is a way for you to access all files in a directory using the FileInfo and DirectoryInfo classes.

string path = @”c:\mydirectory”;

DirectoryInfo myfolder = new DirectoryInfo(path);

FileInfo[] strFiles = myfolder.GetFiles();

foreach (FileInfo myItem in strFiles)
{
myItem.Delete();

// or do whatever you wanna do!

}

  1. No comments yet.
  1. No trackbacks yet.