I have been trying to upload all my data to One Drive for Business and I just realized that many of my files are having white space at the end. I tried a lot and figured out that this script is the solution for the same.
Open Terminal in Mac and type in the below and hit enter. It will take a minute or two and clean up all the spaces. Now, you can try uploading and it will work fine with One Drive.
find . -d -name "* " -type d -exec bash -c 'TO=$(echo "{}" | sed "s/.$//"); FROM=$(echo "{}"); mv "${FROM}" "${TO}"' \;
You can check the reference threadÂ