That looks indeed is if there is a problem with the file structure on that datastore.
Can you check with the datastore browser from the vSphere client if the folder exists and if you descend into that folder ?
Try replacing
Get-ChildItem -Path ("ds:\" + $folder) -Recurse
with
Get-ChildItem -Path ("ds:\" + $folder) -Recurse -ErrorAction SilentlyContinue
that way the script should at least continue after the faulty folder/file