如您所见,以下代码将提取我的“CopierFolderforTestDriveCapstone”文件夹中的所有文件,并将所有文件放入我的“FilesExtracted”文件夹中。我的问题是在所有文件都放入“FilesExtracted”文件夹之后,如何删除所有最近未修改的文件。我只想保留在过去几个月中修改过的文件,或者去年任何一个都可以弄清楚。谢谢 :)
导入系统.IO
公共类 frmExtractionator
Dim txtFiles1 As Control
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim sourceDirectory As String = "E:\CopierFolderforTestDriveCapstone"
Dim archiveDirectory As String = "E:\FilesExtracted"
Try
Dim txtFiles = Directory.EnumerateFiles(sourceDirectory)
If (Not System.IO.Directory.Exists(archiveDirectory)) Then
System.IO.Directory.CreateDirectory(archiveDirectory)
End If
For Each currentFile As String In txtFiles
Dim fileName = currentFile.Substring(sourceDirectory.Length + 1)
File.Move(currentFile, Path.Combine(archiveDirectory, fileName))
Next
Catch eT As Exception
Console.WriteLine(eT.Message)
End Try
End Sub