How to delete all the Google Drive's images that are not used in database (google sheet)

Hi Guys, 

I want to clear all the unused images to save some space, I wonder how we can delete all the images in Google Drive that are not being used in database (Google Sheet), which means that their folder path name are not in any Image Column Type or File Type in database.

Please advise. Thank you

0 6 394
6 REPLIES 6

Could you update if these unused images were also uploaded through AppSheet app in G drive? Also is it correct understanding  that those are now unused because their records have been deleted from the app?

Hi Suvrutt, 

Yes, you are correct

Okay thank you. You can use the approach I suggested to delete unwanted images or Marc's suggestion of using Apps Script.

As I mentioned, you could use the approach similar to one suggested in the tip.

Here it is in short.

1. Add the images folder with option of "Folder As Table" . Please make this table with ADD. UPDATE , DELET option in AppSheet.  Say this folder is called "Products_Images" in G drive and table is also called "Products_Images" in AppSheet.

2. Add a reference action in the table where these images are used. For example if those images are used in the records of the Products table. Please create a reference action on the table Products with a reference rows expression of 

SELECT(Products_Images[_ID], NOT(IN(LEFT([File],8), Products[Product Id])))

The above expression will select the "orphan" records from the folder file where it does not find the corresponding key column present in the Products table, The expression assumes the key of the Products table is based on UNIQUEID()

3. The referenced action for this master reference action can be delete action on the "Products_Images" table.

Once you invoke the master reference action, the unused images will be deleted from the G drive. However please be careful to test the approach on a test app first because this is a delete operation. Any incorrect deletes can cause an issue.

I of course tested it before suggesting.

 

Thank you Sir, will check and feedback asap !

App Script

Or you could try  adding the G drive folder containing images with option of "Folder as table" in the app.

Then typically the approach to delete the unused images will be with action or automation where the list of unused images will be obtained from 

Image_Folder[Image]- Table Containing Valid Images[image]

This is just a broad approach. There may be finer implementation points. The suggested approach though not tested is roughly based on the following tip 

Delete app images or files in an app record from G... - Google Cloud Community

 

Top Labels in this Space