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!

}

Advertisements

Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s