Overview

When creating a large number of files in a shared drive, I encountered a situation where “An error occurred in Google Drive” was displayed and files could no longer be saved.

The likely cause was hitting the following shared drive limitations.

https://support.google.com/a/answer/7338880?hl=ja

Maximum number of items in a shared drive A shared drive can contain a maximum of 400,000 items. This includes files, folders, and shortcuts.

Daily upload limit Individual users can upload up to 750 GB per day to My Drive and all shared drives.

If you hit the second limitation “Daily upload limit,” there is no option but to wait one day.

On the other hand, for the first limitation “Maximum number of items in a shared drive,” you can address it by deleting unnecessary files.

However, simply deleting files leaves them in the trash, and (presumably) the limitation cannot be cleared. So when I searched for a script to empty the shared drive trash, I found the following article.

https://stackoverflow.com/questions/57764248/is-there-a-script-to-empty-google-team-drive-trash-related-folders

Below, I explain how to use the script introduced in that article. This allows you to clear the “Maximum number of items in a shared drive” limitation.

How to Execute the Script to Empty Shared Drive Trash

Copy and paste the following script.

cf}ounnvw}scahttrivcf}i}ilaoofdooernrt}}(brnp(s(/rtritttocyDcrevmirrlaora/aaeyouaern{itcskIFnes.svcohdua)hlioehnenl{eo=l.sd=cAdg0eF(o.tr=(;.iell"igD"ill)ee<osrN<oe{.nSn=iutgslgh({vmr(.ota)debairghrr.es,e(e{iFrhm{=dvietoe=elodrv}DIef.ae)0rdsls()i,.feht{vlinere'ilgdaiset[sIntshihDc(;]e>loti.d"upo+i[;dt+dieid))]Ioe{.tnlieaedmlt,sAeFr"{rg,'ossm)tuA.rpliapltsoDehrrmetisdsv;.Aellsel'nD:grttirhvu)ees,':'tcrourep}o)ra':'drive','supportsAllDrives':true,'q':'trashed=true'}

First, access the following URL.

https://script.google.com/home

Then, click “New project” as shown in the figure below.

Paste the script above. After pasting, change the “driveId” on the first line and click the “Save” button at the top of the screen.

Next, add a service. Add the “Drive API” from “Services.”

Then click the “Run” button.

Authorization will be requested the first time.

As shown below, files are deleted in batches of 100.

After a certain period of time, an error will occur as shown below. In that case, click the “Run” button again.

Summary

There may be better solutions, but I hope this serves as a helpful reference for those experiencing “An error occurred in Google Drive” or similar issues.

Addendum

2022.05.06

GAS reportedly has a 6-minute script execution time limit.

https://developers.google.com/apps-script/guides/services/quotas#current_limitations

Therefore, by setting the above script to run every 5 or 10 minutes, the trash can be emptied automatically.

Specifically, select Triggers as shown below and click the “Add Trigger” button.

Then select “Time-driven,” “Minutes timer,” and “Every X minutes” as shown below.

I hope this is helpful.