Directory.GetFiles get today's files only

前端 未结 7 640
青春惊慌失措
青春惊慌失措 2021-01-04 01:02

There is nice function in .NET Directory.GetFiles, it\'s simple to use it when I need to get all files from directory.

Directory.GetFiles(\"c:\\\\Files\")
<         


        
7条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 01:41

    You need to get the directoryinfo for the file

    public List getTodaysFiles(String folderPath)
    {
        List todaysFiles = new List();
        foreach (String file in Directory.GetFiles(folderPath))
        {
            DirectoryInfo di = new DirectoryInfo(file);
            if (di.CreationTime.ToShortDateString().Equals(DateTime.Now.ToShortDateString()))
                todaysFiles.Add(file);
        }
        return todaysFiles;
    }
    

提交回复
热议问题