Bạn có thể sử dụng Path.GetFileNameđể lấy tên tệp từ đường dẫn đầy đủ
private string[] pdfFiles = Directory.GetFiles("C:\\Documents", "*.pdf")
.Select(Path.GetFileName)
.ToArray();
CHỈNH SỬA: giải pháp trên sử dụng LINQ , vì vậy nó yêu cầu tối thiểu .NET 3.5. Đây là một giải pháp hoạt động trên các phiên bản trước đó:
private string[] pdfFiles = GetFileNames("C:\\Documents", "*.pdf");
private static string[] GetFileNames(string path, string filter)
{
string[] files = Directory.GetFiles(path, filter);
for(int i = 0; i < files.Length; i++)
files[i] = Path.GetFileName(files[i]);
return files;
}