How to get only filenames within a directory using c#?

后端 未结 7 1717
闹比i
闹比i 2020-12-04 15:05

When I use the line of code as below , I get an string array containing the entire path of the individual files .

private string[] pdfFiles = Directory.GetF         


        
7条回答
  •  甜味超标
    2020-12-04 15:36

    You can simply use linq

    Directory.EnumerateFiles(LoanFolder).Select(file => Path.GetFileName(file));
    

    Note: EnumeratesFiles is more efficient compared to Directory.GetFiles as you can start enumerating the collection of names before the whole collection is returned.

提交回复
热议问题