Have you ever had the need for a function to copy every file in a directory… wait no longer… here is a recursive way to copy files:
Sub CopySelectedFiles(ByVal strSourceDirectory As String, ByVal strDestDirectory As String, ByVal strSearchString As String)Dim dirInfo As New DirectoryInfo(strSourceDirectory)Dim fsInfo As FileSystemInfoFor Each fsInfo In dirInfo.GetFileSystemInfosDim strDestFileName As String = Path.Combine(strDestDirectory, fsInfo.Name)If TypeOf fsInfo Is FileInfo And fsInfo.Name.IndexOfAny(strSearchString) > -1 ThenFile.Copy(fsInfo.FullName, strDestFileName, True) ' 'This will overwrite files that already existElse
CopySelectedFiles(fsInfo.FullName, strDestFileName, strSearchString) 'we have found a subdirectory
End IfNext
End Sub