I've written a recursive script with a couple of if statements to append all files/folders in in vba using FSO but it takes forever, and I'm looking for other methodologies, or faster ways to append files. Is using the DIR or Call shell a faster way? Any reasoning would be appreciated.
Option Explicit
Sub BackUpEverything()
Dim Sourcefolder As String
Const DestinationFolder As String = "C:\Users\Person1\FolderX"
Dim i As Long
Dim copyfolders(3) As String
copyfolders(0) = "C:\Users\FolderA"
copyfolders(1) = "C:\Users\FolderB"
copyfolders(2) = "C:\Users\FolderC"
copyfolders(3) = "C:\Users\FolderD"
For i = 0 To 3
Sourcefolder = copyfolders(i)
backupfiles Sourcefolder, DestinationFolder
Next i
Mgsbox "Done"
End Sub
Sub backupfiles(Sourcefolder As String, DestinationFolder As String)
Dim FSO As filesystemobject
Dim oFile As File
Dim oFolder As Folder
Set FSO = New filesystemobject
If Not FSO.folderexists(DestinationFolder) Then FSO.Createfolder DestinationFolder
On Error Resume Next
For Each oFile In FSO.Getfolder(Sourcefolder).Files
If FSO.getextensionname(oFile.Path) <> "pdf" Then
FSO.copyfile oFile.Path, DestinationFolder & " \ " & oFile.Name
Else
End If
Next oFile
On Error Resume Next
For Each oFolder In FSO.Getfolder(Sourcefolder).SUbfolders
backupfiles oFolder.Path, DestinationFolder & " \ " & oFolder.Name
Next oFolder
End Sub