【发布时间】:2014-02-02 09:24:17
【问题描述】:
Private Shared Sub CopyDirectory(sourcePath As String, destPath As String)
If Not Directory.Exists(destPath) Then
Directory.CreateDirectory(destPath)
End If
For Each file__1 As String In Directory.GetFiles(sourcePath)
Dim dest As String = Path.Combine(destPath, Path.GetFileName(file__1))
Try
File.Copy(file__1, dest) '<--------this part is showing error
Catch ex As Exception
File.Replace(file__1, dest, dest, 0)
End Try
Next
For Each folder As String In Directory.GetDirectories(sourcePath)
Dim dest As String = Path.Combine(destPath, Path.GetFileName(folder))
CopyDirectory(folder, dest)
Next
End Sub
【问题讨论】:
-
您正在尝试复制已存在于同一目录中的文件。更改目标目录或更改文件名。