Using the search i've had no problems figuring out how to copy the contents of a folder from one place to another.
But what about copying sub-folders? I'd like to also copy all the sub-folders. Take a look at this:What if there are a few sub-folders in the "test" folder? How can i copy them and all their contents? I know i'll need a recursive loop, but how do i identify the folder?VB Code:
'Using this import: Imports System.IO 'Locate where the program is Dim sAppPath As String = System.Environment.CurrentDirectory 'Use the test directory with sample files in it Dim xSourceFolder As New DirectoryInfo(sAppPath & "\test") Dim xDestinationFolder As New DirectoryInfo(sAppPath & "\test2") 'Removes previous instance of the folder and any sub-directories, then creates it fresh If xDestinationFolder.Exists = True Then xDestinationFolder.Delete(True) xDestinationFolder.Create() 'Copies each file from the source foldr into the destination folder Dim xFile As FileInfo For Each xFile In xSourceFolder.GetFiles xFile.CopyTo(xDestinationFolder.FullName & "\" & xFile.Name) Next xFile Beep()




Reply With Quote