This can be done using the ownCloud Console (occ).
All you need is to go where the web app is, which is usually /var/www/owncloud and then run:
sudo -u www-data php occ files:scan –all
This will rebuild the whole files cache. This is the solution for data that sometimes appear as existing on the filesystem, but actually they don’t and are just orphan entries in the DB.