CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, September 25, 2006

List Files Inside a Directory by filetype in .NET

Description: Very simple, receives an input string example: myapp.exe C:\folder\ and it will give out each filename string.

using System;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
namespace listaArquivosVisiveisConsole
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
if (args[0] != "")
{
Console.WriteLine("Checking: " + args[0]);
//string teste =
//File.OpenWrite(args[0]).ToString();
DirectoryInfo di =
new DirectoryInfo(args[0]);
FileInfo[] rgFiles = di.GetFiles("*.txt");
foreach(FileInfo myFilesList in rgFiles)
{
Console.WriteLine(myFilesList.Name);
}
}
else
{
return;
}
}
}
}

Post a Comment