Saturday, January 10, 2015

Get Files from Directory using C#

Sample code to get the list of files from the source Directory. You can also add filter to search the specific file type only.

Namespace :
using System.IO;


Code:

Directory.GetFiles returns string array with files names.

string[] files = Directory.GetFiles(@"c:\Test\");


You can also search the files with specific pattern.

string[] files = Directory.GetFiles(@"c:\Test\", "*.txt");


To get the list of files from directory including the sub directories,

string[] filePaths = Directory.GetFiles(@"c:\Test\", "*.txt",SearchOption.AllDirectories);

1 comment:

  1. The Evolution of the Gambling Casino: The Most Innovative Way
    Evolution has developed a wide array of casino 영주 출장안마 games, including 춘천 출장안마 slot machines, 상주 출장샵 blackjack, roulette and live dealer games. Most 이천 출장마사지 of these games 아산 출장샵

    ReplyDelete