convert a FileInfo array into a String array C#

前端 未结 4 1154
春和景丽
春和景丽 2021-01-05 05:17

I create a FileInfo array like this

 try
            {
                DirectoryInfo Dir = new DirectoryInfo(DirPath);
                FileInfo[] FileList =          


        
4条回答
  •  無奈伤痛
    2021-01-05 06:00

    Try this one

    DirectoryInfo directory = new DirectoryInfo("your path");
    List Files = (directory.GetFiles().Where(file => file.LastWriteTime >= date_value)).Select(f => f.Name).ToList();
    

    If you don't want a filter with date, you can simply convert with the below code

    List logFiles = directory.GetFiles().Select(f => f.Name).ToList();
    

    If you need the full path of the file, you can use FullName instead of Name.

提交回复
热议问题