How to do rclone list orphan files?

Hello,

In Google Drive web UI you can search "is:unorganized owner:me" that list all files owned by you with status orphaned (not belonged to any folder/not accessible)
You then can "Add to My Drive" to be able to access it or "Delete Permanently" which will free up your storage quota.

However above task doesn't always work in Google Drive Web UI because it is slow, it could result in "server error, please try later" which mean you can never see your orphaned files, or never able to free up your storage quota.

How can I do above operation within rclone?
At the very least I'd like to list all files I owned that is orphaned/not belong to any folder/not accessible so that I can permanently delete them.

Here is the typical example when orphan occurred:

User A create folder AA and share it with User B (read,write,view,dl permission).
User B create file B.TXT(read,write,view,dl permission) inside folder AA.
User A delete file B.TXT via Google Drive File Stream or Web UI.
File B.TXT became orphan, it still count towards User B storage quota and it is very difficult for User B to access it from Web UI. The file is impossible to list or access from User A perspective.

It seems that Google save all orphaned files as hidden files/folders in Root.

Reference:
http://www.syncdocs.com/forums/topic/handling-orphaned-files-and-folders


I didn't know you could put API query commands in the search box - that is useful!

I also didn't know about orphaned files.

Rclone can't do this at the moment, however with a bit of work it could. I could imagine another flag like --drive-shared-with-me say --drive-orphaned which only showed the orphaned files.

What do you think? Would you like to help implement something like this?

It would be great to have such flags because the ones Google provide in their Web UI is very unreliable (only works when you have small collection of files)

Unfortunately I don't posses any programming skill in golang despite me graduated as CS long time ago.
I would like to go back into programming, and have been slowly reading golang, but I would not know which Drive API to start looking at to implement such task above, or which rclone part of code I should start looking at.

Also, do you think implementing this in rclone would still work when the Admin of the Org disable "Search Console" feature ?
If we can implement the flag regardless of above then maybe it is worth it.

For example, in my domain it works because as an Admin I enabled that in my Org, but I know that most/many Admins in other Orgs or Universities disable "Search Console" feature because it is the default setting. So in this case, API query "is:unorganized owner:me" doesn't work in Google Web UI.

I also just found out this feature after I realize my storage usage doesn't get reduced after removing a lot of files via another user.
It turns out all my files that I deleted that way became orphaned and still counts towards my storage usage.
I have probably 4TB worth of orphaned files in total of several hundreds thousands of small/medium sized files. And so Google Web UI most of the time even failed to execute API query because the time it takes to list the files.

Unfortunately it looks like the drive API doesn't support that directly.

I expect it is possible to do it with a bit of head scratching though. Perhaps that is why it takes a long time in the drive interface.

Indeed head scratching.
I tried this: https://script.google.com/d/1-Dikk2mt71bG12WPpzRcE9dsR_RaNhQUX0XP8oku08yeqo6WcrvjH7_9/edit?usp=sharing
but the result is weird... I found other people's orphaned files, but not mine.

!!!

I think the way to do it is to to a search for all files owned by me then

  • if a file has no parents it is definitely orphaned

I don't think it is possible to express len(parents) == 0 in the query language though