Fix OneDrive sync problems

OneDrive has a limitation whereby it cannot sync a path longer than 255 characters, and additionally it will not accept files with the following characters in the path:

/ \ > < : * " ? |

It won’t accept a space at the start or end of a filename, or a dot on the end of a filename. These are quite annoying if you’re using a Mac, as none of those restrictions apply to MacOS! I recently put this script together in PHP to resolve hundreds of such issues with a large structure of folders I wanted to backup. Doing it by hand would take hours, so I needed an automated fix.

Script to fix Mac sync problems with OneDrive special characters

Script to fix Mac sync problems with OneDrive special characters

Please note: the content above is an image due to a problem with WordPress rendering it correctly! Here, as an attachment, is the PHP file: fix_onedrive.php

If you have a lot of folders to fix, you can call this recursively easily from the command line (ie. Terminal). Just save the script to a PHP file (I use fix_onedrive.php) and set the execution bits (chmod +x fix_onedrive.php). Then you can use the standard Unix find command to call this script over every folder:

find PATH_TO_ONEDRIVE -type d -exec ./fix_onedrive.php {} ';'

I am sure that a neater script – possibly even doing everything in AppleScript – would be effective, but since this worked for me and the only other fixes I saw cost nearly $200, I thought I’d better post it. Lastly, I must say I find it incredible that these restrictions exist in the first place, and hope that Microsoft are aware that they pose a significant barrier to those of us wanting to use OneDrive. Let’s hope it can be resolved properly in an update.

One thought on “Fix OneDrive sync problems

  1. Around August 2015 I finally decided that OneDrive is fundamentally not right for me. The way it hobbles storage descriptors (and performance issues) are too severe, so even though it is a good free addition to an Office 365 subscription I abandoned it.

    I have moved to Dropbox, where an annual 1TB subscription is £79. Considering the time I won’t be spending fixing it, I think this is quite good value!