The problem here is that you want to copy all source files (including those in sub folders) into 1 destination folder. At this point there are chances that files will have the same file name and you may have files overwritten during the copy or files will be skipped as it will see it as a duplicate.
You're trying to achieve this with the following code
count = 0
Do While fso.FileExists(dest)
count = count + 1
dest = fso.BuildPath(testfolder, basename & "_" & count & "." & extension)
Loop
The problem is, you'll not know which file corresponds to which source file.
I suggest you rename the file as the full path. So, let's assume your source folder looks like:
In both the FolderExample and sub01 there is a file called image01.jpg.
I've used the underscore here to separate each folder (which may or may not be realistic for you). But by creating this new file name it means you cannot overwrite any other file with the same name!
Now, if you need to use the file again, the problem is the file name has changed. The good thing about using the underscore here is you can program another application to copy the file, split by underscore and then create the full path, get the file name and copy files accordingly.
This means, you can replace
If LCase(extension) = "env" Then
dest = fso.BuildPath(testfolder, f.Name)
count = 0
Do While fso.FileExists(dest)
count = count + 1
dest = fso.BuildPath(testfolder, basename & "_" & count & "." _
& extension)
Loop
f.Move dest
End If
with
If LCase(extension) = "env" Then
dest = fso.BuildPath(testfolder, f.Name)
if not (fso.FileExists(dest)) then
f.Move dest
end if
End If