Vb.net 将子目录复制到目录
参考此问题/代码: 我正在尝试将一堆子目录复制到另一个目录。我想更新此代码:Vb.net 将子目录复制到目录,vb.net,visual-studio-2010,directory,copy,Vb.net,Visual Studio 2010,Directory,Copy,参考此问题/代码: 我正在尝试将一堆子目录复制到另一个目录。我想更新此代码: Dim fso As System.Object = New System.Object fso = CreateObject("scripting.filesystemobject") fso.copyfolder(sour, dest) 但是我得到了这个错误: System.IO.DirectoryNotFoundException:找不到 路径“C:\Temp\Summer2011\Newf
Dim fso As System.Object = New System.Object
fso = CreateObject("scripting.filesystemobject")
fso.copyfolder(sour, dest)
但是我得到了这个错误:
System.IO.DirectoryNotFoundException:找不到
路径“C:\Temp\Summer2011\Newfolder\Copy of New Text Document.txt”。在
System.IO.\u E\u Error.WinIOError(Int32 errorCode,字符串maybeFullPath)
在System.IO.File.InternalCopy(字符串sourceFileName,字符串
destFileName,Boolean overwrite)在System.IO.File.Copy(字符串
sourceFileName、字符串destFileName)…等
使用此.NET版本
Public Overrides Sub OnClick()
Dim sour As String = "C:\Temp243"
Dim dest As String = "C:\Temp\Summer2011\"
CopyDirectory(sour, dest)
End Sub
Private Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String)
If Directory.Exists(DestPath) Then
Directory.CreateDirectory(DestPath)
End If
For Each File As String In Directory.GetFiles(SourcePath)
Dim dest As String = IO.Path.Combine(DestPath, IO.Path.GetFileName(File))
IO.File.Copy(File, dest) '<<<ERROR HERE
Next
For Each folder As String In Directory.GetDirectories(SourcePath)
Dim dd As String = IO.Path.Combine(DestPath, IO.Path.GetFileName(folder))
CopyDirectory(folder, dd)
Next
End Sub
Public覆盖子OnClick()
暗酸性为String=“C:\Temp243”
Dim dest As String=“C:\Temp\Summer2011”
CopyDirectory(sour,dest)
端接头
私有子CopyDirectory(ByVal SourcePath作为字符串,ByVal DestPath作为字符串)
如果Directory.Exists(DestPath),则
目录.CreateDirectory(DestPath)
如果结束
对于目录.GetFiles(SourcePath)中的每个文件作为字符串
Dim dest As String=IO.Path.Combine(DestPath,IO.Path.GetFileName(文件))
IO.File.Copy(File,dest)“尝试使用该方法
希望这有帮助。该目录路径存在吗?
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(sourceDirectory, destinationDirectory)