Ek bir yanıt olarak (veya mevcut yanıtları birleştirmek için) bunu sizin için DirectoryInfo sınıfı içinde gerçekleştirmek için bir uzantı yöntemi yazabilirsiniz. İşte oldukça hızlı yazdım, dizin adları veya değişiklik için diğer kriterler, vb sağlamak için süslenebilir bir örnek:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace DocumentDistributor.Library
{
public static class myExtensions
{
public static string[] GetFileNamesWithoutFileExtensions(this DirectoryInfo di)
{
FileInfo[] fi = di.GetFiles();
List<string> returnValue = new List<string>();
for (int i = 0; i < fi.Length; i++)
{
returnValue.Add(Path.GetFileNameWithoutExtension(fi[i].FullName));
}
return returnValue.ToArray<string>();
}
}
}
Düzenleme: Ben de dizinin yapımını elde etmek için LINQ kullanılan bu yöntem muhtemelen basitleştirilmiş veya awesome-ified olabilir düşünüyorum, ama LINQ bu tür bir örnek için yeterince hızlı yapmak için deneyimim yok.
Edit 2 (neredeyse 4 yıl sonra): İşte kullanacağım LINQ ified yöntemi:
public static class myExtensions
{
public static IEnumerable<string> GetFileNamesWithoutExtensions(this DirectoryInfo di)
{
return di.GetFiles()
.Select(x => Path.GetFileNameWithoutExtension(x.FullName));
}
}