30 Eylül 2009 Çarşamba

Get File Names with C#

You can use the following code, if you want to get file names in a directory using C#:

using System;
using System.IO;

class Program
{
static void Main()
{
string[] array1 = Directory.GetFiles(@"C:\");

// Put all txt files in root directory into array2.
string[] array2 = Directory.GetFiles(@"C:\", "*.txt");

Console.WriteLine("Files:");
foreach (string name in array1)
{
Console.WriteLine(name);
}

// Display all txt files.
Console.WriteLine("txt Files:");
foreach (string name in array2)
{
Console.WriteLine(name);
}
}
}

Hiç yorum yok: