Moving files to a different directory depending on modified date information
Posted on 2006-07-11
If file are older then 40 days, then
' check file modified date
'create a sub folder with year file modifed
'create a another suffolder with month modified
'then move file to month subfolder.
'this is my working code I have so far how can i implement in my current code.
'this current code moves all files that are older then 40 days but it doesn't check the file modified year and month and it 'doesn't create folders to the specific year and month.
Dim daysOld As Integer = AppSettings("daysOld")
Dim di As New DirectoryInfo(searchDir)
Dim fi() As FileInfo = di.GetFiles("*.txt")
Dim dirs() As DirectoryInfo = di.GetDirectories()
For Each fInfo As FileInfo In fi
If File.GetLastWriteTime(fInfo.FullName) < Today.AddDays(-40) Then
If Not Directory.Exists(Dest) Then _
File.Move(fInfo.FullName, Dest & "\" & fInfo.Name)
' Go through all the directories in the current directory
For Each dir As DirectoryInfo In dirs
Catch ex As Exception