0
您可以看到以下代碼將提取我的「CopierFolderforTestDriveCapstone」文件夾中的所有文件,並將它們放入我的「FilesExtracted」文件夾中。我的問題是,所有文件都放入「FilesExtracted」文件夾後,如何刪除最近未修改的所有文件。我只想保留過去幾個月內修改過的文件,或者在過去的一年中任何一個都能很好地解決問題。謝謝:)刪除複製到文件夾中的未修改文件
進口System.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