我会将所有文件复制到另一个位置,此程序将过滤-7天,当它复制到另一个位置时,它会显示所有文件都复制在.log中。当我将所有文件复制到该位置时,我仍然难以获取日志。请参阅以下内容:
Imports System
Imports System.IO
Public Class Form1
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim DirectoryToCopy As String
Dim NewCopy As String
Dim d As Date = Date.Today
d = d.AddDays(-7)
DirectoryToCopy = "c:\test\hmm.gdb"
NewCopy = "D:\Data\hmm.gdb"
'NewCopy = "D:\Data\hmm.gdb" & d.AddDays(-7)
Dim objWriter As New System.IO.StreamWriter("D:\Data\update.log")
If System.IO.Directory.Exists(DirectoryToCopy) = True Then
My.Computer.FileSystem.CopyDirectory(DirectoryToCopy, NewCopy, True)
Directory.GetFiles(NewCopy, d)
d = Directory.GetCreationTime(NewCopy)
System.IO.File.Copy(DirectoryToCopy, NewCopy)
' System.IO.File.Copy(NewCopy, "D:\Data\update.log")
'objWriter.WriteLine("file copy")
'objWriter.Close()
'MsgBox("File Copied")
End If
End Sub
End Class
答案 0 :(得分:1)
这里......我改变了你的代码..
Imports System.IO
Public Class Form1
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim SourceFoDir As String= "C:\test"
Dim TargetDir As String= "D:\Data"
Dim NewCopy As String
Dim oW As New System.IO.StreamWriter
Dim d As Date = Date.Today
d = d.AddDays(-7)
If Not My.Computer.FileSystem.DirectoryExists(DirectoryToCopy) Then
oW = My.Computer.FileSystem.OpenTextFileWriter("D:\Data\update.log", True)
For Each f In Directory.GetFiles(DirectoryToCopy)
file.copy(f & d.Date.ToString, TargetDir)
oW.WriteLine(f & d.Date & " copied")
Next
oW.Close()
End If
End Sub
End Class