我有以下代碼複製一切,除了文件1在正確的地方,文件2 &文件3.VB.Net如何通過文件夾itterate和複製文件
來源:「C:\目錄「 目標: 」C:\ tmp目錄\備份「
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應該去裏面的 」目錄「 中的文件夾,但它不斷出現在了 」備份「 文件夾中。
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」文件夾中?
檢查target.CreateSubdirectory(項目名稱& 「\」 &MyDir.Name)返回DirInfo的哪個目錄 – Patel
什麼是變量'projectName' ?它不在參數列表中或在您的功能中定義。它是你的類的成員變量嗎? – mortb
什麼是file1,file2,file3的源文件的路徑? –