How to remove leading whitespace in a folder for OneDrive upload on mac os
Here is a script that’s dedicated to fix this issue for OneDrive on the Mac.

https://github.com/soundsnw/mac-sysadmin-resources/blob/master/scripts/fix-onedrive-filenames-apfs.sh

It is quite sophisticated and very well documented.

If you don’t have JAMF - remove those from the end - they fill fail harmlessly I believe if you don’t have the JAMF framework installed.
It checks for APFS and makes a full backup of the existing files.
It notifies you what it’s doing.
It fixes folders first, then files.
It trims white space from the front and end of files and folders and also corrects illegal characters like /
It tries to catch errors, clean up, prevent sleep, avoid spotlight going ballistic while the files are being renamed, etc..
There’s nothing about this script I don’t like, to be honest.

It has no warranty, but please ask if you think you need help modifying it. I did not write it, but the community of mac administrators that makes and shares these are some of the best resources I know for great tools.