Supraja

Supraja

  • NA
  • 25
  • 7.7k

How to copy only one month files in vb.net

Sep 27 2016 10:04 PM
I am trying to copy files from one folder to another folder, i has to get only one month files for example the files should copy only from 27/8/2016 to till date if i run now, i coded for this but its not working its copying January files also can anyone suggest what need to change.
 
 
Public Sub FileCopy(src As String, dest As String)
Dim lastOneMonth As DateTime = DateTime.Now.AddMonths(-1)
Dim DateModified = File.GetCreationTime("D:\Working Files\Commercial Team\Retail\Billing\Invoices\2016")
If DateModified >= lastOneMonth Then
Dim totalFiles As Integer = 0
Dim filePath As String = Path.GetDirectoryName(file__1)
Dim fileName As String = Path.GetFileNameWithoutExtension(file__1.ToString())
If fileName.Contains("_I-") OrElse fileName.Contains("_IS") OrElse fileName.Contains("_C-") AndAlso fileName.Length = 10 Then
Dim newFullName As String = dest & "\" & fileName & ".pdf"
File.Copy(file__1.ToString(), newFullName, True)
totalFiles += 1
End If
Next
Dim tFiles As Integer = totalFiles
Catch ex As IOException
End Try
end if
End Sub 
 

Answers (1)