【发布时间】:2021-06-14 13:17:05
【问题描述】:
我需要合并这些在每个目录中都有大量文件的文件夹。我会使用 folder.copy 但这需要很长时间。
我大部分时间都在使用 xcopy 进程来处理这个问题,但是我从 xcopy 收到错误消息,说没有重复项时存在重复项。所以我试图找到一个与 xcopy 一样快甚至更快的可靠工作。
我之前尝试过的是:
Private Sub MergeF(ByVal TargetFolder As String, ByVal MergeeFolder As String)
For Each F As String In IO.Directory.GetFiles(MergeeFolder)
If IO.File.Exists(IO.Path.Combine(TargetFolder, IO.Path.GetFileName(F))) Then
Dim FileA As New IO.FileInfo(IO.Path.Combine(
MergeeFolder, IO.Path.GetFileName(F)))
Dim FileB As New IO.FileInfo(IO.Path.Combine(
TargetFolder, IO.Path.GetFileName(F)))
If FileA.Length <> FileB.Length Then
Dim index As Integer = 1
Do
Dim NewFileName = IO.Path.Combine(TargetFolder,
IO.Path.GetFileName(F.Insert(F.Length - 4, CStr(index))))
If IO.File.Exists(NewFileName) Then
index += 1
Else
IO.File.Copy(F, NewFileName)
IO.File.Delete(F)
Exit Do
End If
Loop
End If
Else
IO.File.Move(IO.Path.Combine(MergeeFolder, IO.Path.GetFileName(F)),
IO.Path.Combine(TargetFolder, IO.Path.GetFileName(F)))
End If
Next
End Sub
【问题讨论】:
-
XCopy 按名称确定重复项,而不是按内容或文件日期。
标签: vb.net file merge copy xcopy