Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy Sub directories to directory
    primarykey
    data
    text
    <p>Referencing this question/code:</p> <p><a href="https://stackoverflow.com/questions/1066674/how-do-i-copy-a-folder-and-all-subfolders-and-files-in-net">How do I copy a folder and all subfolders and files in .NET?</a></p> <p>I'm trying to copy a buntch of sub directories to a different directory. I'm wanting to update this code:</p> <pre><code>Dim fso As System.Object = New System.Object fso = CreateObject("scripting.filesystemobject") fso.copyfolder(sour, dest) </code></pre> <p>However I'm getting this error:</p> <blockquote> <p>System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Temp\Summer2011\Newfolder\Copy of New Text Document.txt'. at System.IO._E_Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite) at System.IO.File.Copy(String sourceFileName, String destFileName)...etc</p> </blockquote> <p>With this .NET version</p> <pre><code> 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) '&lt;&lt;&lt;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 </code></pre> <p>Is there a easier way of doing this with less lines of code like the fso As System.Object version? Also, I have System.IO imported however File.Copy and Directory.GetFiles are not colored blue, could this be the issue? I have the System loaded as a reference.</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload