'Copy files from one folder to another automatically by today's date
I need to make a program in Visual Studio that copy files from one folder to another automatically by today's date. I've this code right here that a friends gives me but I don't know how to make it work. Could someone help me pls?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim lvCreationTime As Date
Dim lvStr_Diretoria As String = ""
lvStr_Diretoria = "C:\"
Dim ficheiros() As String = IO.Directory.GetFiles(lvCreationTime)
For Each file As String In ficheiros
' Do work, example
lvCreationTime = IO.File.GetCreationTime(file)
'Dim text As String = IO.File.ReadAllText(file)
If DateDiff(DateInterval.Day, lvCreationTime, Now) = 0 Then
'file to comunicate
End If
Next
'
'If Not IO.File.Exists() Then
'End If
Solution 1:[1]
you can use the code below
Dim folderA As String = "C:\FolderA"
Dim folderB As String = "C:\FolderB"
'read all files from folderA
Dim infoDir As New DirectoryInfo(folderA)
Dim files As FileInfo() = infoDir.GetFiles()
'use linQ to filter by date; below from Now but you can specify what you want
Dim filter As List(Of FileInfo) = (From f In files Where f.CreationTime.Date.ToShortDateString() = Now.ToShortDateString() Select f).ToList()
' and here you move from folderA to folderB
For Each i In filter
My.Computer.FileSystem.MoveFile(i.FullName, folderB & "\" & i.Name)
Next
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Giuseppe Pistorino |