Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Basic Deleting Unmodified Files
    text
    copied!<p>The following code will extract files from one Folder and Place them another as you can see. But I am trying to delete the files that have not been modified in the past 3 months, and it does not delete any files at all.</p> <p>Code:</p> <pre><code>Imports System.IO Public Class 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 currentFileLoc As String In txtFiles Dim fileName = currentFileLoc.Substring(sourceDirectory.Length + 1) File.Move(currentFileLoc, Path.Combine(archiveDirectory, fileName)) Try Dim di As DirectoryInfo = New DirectoryInfo(sourceDirectory) Dim fi As FileInfo() = di.GetFiles() For Each currentFile As FileInfo In fi File.Move(currentFile.FullName, Path.Combine(archiveDirectory, currentFile.Name)) Dim dt As DateTime = currentFile.LastWriteTime ' Add 3 months to the last write and check if it is less than today ' If dt.AddMonths(3) &lt; DateTime.Today Then File.Delete(currentFile.FullName) End If Next Catch eT As Exception Console.WriteLine(eT.Message) End Try Next Catch eT As Exception Console.WriteLine(eT.Message) End Try End Sub End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload