HowTo copy entire folders with contents to a different folder?
-
I am looking quite a while to find the source code for copying an entire folder + contents to a target folder. Can anyone help me? Because if i dont have that code, the program im working on can't be finished. Thanks, Zaegra :) --Zaegra--
From MSDN (http://msdn.microsoft.com) The following example determines whether a specified directory exists, deletes it if it does, and creates it if it does not. This example then moves the directory, creates a file in the directory, and counts the files in the directory. [Visual Basic] Imports System Imports System.IO Public Class Test Public Shared Sub Main() 'Specify the directories you want to manipulate. Dim path As String = "c:\MyDir" Dim target As String = "c:\TestDir" Try ' Determine whethers the directory exists. If Directory.Exists(path) = False Then ' Create the directory. Directory.CreateDirectory(path) End If If Directory.Exists(target) Then ' Delete the target to ensure it is not there. Directory.Delete(target, True) End If ' Move the directory. Directory.Move(path, target) 'Create a file in the directory. File.CreateText(target + "\myfile.txt") 'Count the files in the target. Console.WriteLine("The number of files in {0} is {1}", _ target, Directory.GetFiles(target).Length) Catch e As Exception Console.WriteLine("The process failed: {0}", e.ToString()) End Try End Sub