我有以下代码将所有内容复制到正确的位置,但文件 1、文件 2 和文件 3 除外。
来源:“C:\dir” 目标:“C:\tmp\Backup”
Public Sub CopyDirectory(source As DirectoryInfo, target As DirectoryInfo)
'Recursively call the DeepCopy Method for each Directory
For Each MyDir As DirectoryInfo In source.GetDirectories()
CopyDirectory(MyDir, target.CreateSubdirectory(projectName & "\" & MyDir.Name))
Next
' Go ahead and copy each file in "source" to the "target" directory
For Each MyFile As FileInfo In source.GetFiles()
If Not (File.Exists(Path.Combine(target.FullName, MyFile.Name))) Then
MyFile.CopyTo(Path.Combine(target.FullName, MyFile.Name))
Else
MessageBox.Show("File already exist")
End If
Next
End Sub
文件 1、2 和 3 应该放在“Dir”文件夹中,但它一直显示在“Backup”文件夹中。
C:\
|_ tmp
|_ Backup
|_ Dir
|_ Folder 1
|_ File 11
|_ File 12
|_ File 13
|_ Folder 2
|_ File 21
|_ File 22
|_ File 23
|_ Folder 3
|_ File 31
|_ File 32
|_ File 33
|_ File 1
|_ File 2
|_ File 3
如何确保将文件 1、2 和 3 复制到“Dir”文件夹中?