Wednesday, October 22, 2014

Clearing Your OneDrive Cache

For those of you that use OneDrive extensively, you may find that your disk drive is quickly running out of space. This is because OneDrive caches files on your Office temporary folder. These can get very large because it creates a cache file that is just a copy of the file it is trying to sync. I'm not sure what will trigger the cache files to clear out, so I created this batch script to clean out the files when I want. Just save this to a .bat file and run it.

Note: the %temp% directory, at this time, is something like "c:\users\xxxUSERxxx\AppData\Local\Microsoft\Office\15.0\OfficeFileCache"

cd %temp%
cd ..
cd microsoft
cd office
cd 15.0
cd OfficeFileCache
forfiles /m *.fsd  /d -1 /c "cmd /c del @file : date >= 1 days >NUL"
forfiles /m *.fsf  /d -1 /c "cmd /c del @file : date >= 1 days >NUL"


This script tries to avoid any currently opened files by starting with yesterdays  files (and older.) Technically you could just delete everything with *.* and windows will just ignore all the files that are open because OneDrive is trying to sync them at the moment and has them locked. What I'm trying to avoid with my approach is to avoid deleting the  "" files that OneDrive is using to manage the file syncing.

On a related note, When you run a repair on OneDrive it creates  *.Oldx versions of your OfficeFileCache folder in the %temp%\microsoft\office\15.0 directory with folder names like OfficeFileCache.old1, OfficeFileCache.Old2. These are copies of the folders before the repair executes. These can be deleted - if you are comfortable with the files you have on your OneDrive locally and in the cloud.