我在一个文件夹中有一些文件列表(.txt),每个文件夹都有一些DateModified。
现在我需要选择从今天到日期前2天的所有文件,我需要将其移动到另一个文件夹。
任何人都可以告诉我如何根据修改日期获取它们?
答案 0 :(得分:0)
尝试我写过的方式:
Private Sub Test() Handles Button1.Click
' Get the file paths inside the textfile.
Dim FilePaths As String() =
IO.File.ReadAllLines("C:\File.txt")
' Get the file information of each filepath.
Dim Files As IO.FileInfo() =
(From FilePath As String In FilePaths
Where Not String.IsNullOrEmpty(FilePath)
Select New IO.FileInfo(FilePath)).ToArray
' Sort them by Date-Modified, and keep only files modified between 2 days to today.
Files = (From [File] As IO.FileInfo In Files
Order By [File].LastWriteTime Ascending
Where [File].LastWriteTime.AddDays(-2).Year = Today.AddDays(-2).Year _
AndAlso [File].LastWriteTime.AddDays(-2).Month = Today.AddDays(-2).Month _
AndAlso [File].LastWriteTime.Day >= Today.AddDays(-2).Day).ToArray
' Iterate the files (to copy them for example).
For Each [File] As IO.FileInfo In Files
MsgBox(String.Format("Name: {0} | DateModified: {1}",
[File].FullName, [File].LastWriteTime.ToShortDateString & " " & Today.ToShortDateString))
Next [File]
End Sub
End Sub