Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically delete files in google drive

Is there an app or script I can use that will automatically delete files (specifically .jpg) in my root google drive directory after 30 days or when my google drive is close to getting full.

I have .jpg attachments sent over from my email automatically to my google drive.It is just filling up my google drive space and I would like them to be automatically deleted.

Thanks.

like image 569
user2029514 Avatar asked Jan 31 '13 15:01

user2029514


People also ask

Why Google Drive is automatically delete files?

There are many users who say Google Drive deletes their files and they did not receive any messages. Why is Google Drive deleting my files? As revealed by Google, the issue may be caused by the latest storage policy.

How do I automatically delete files after a certain time?

You can free up space and keep things organized by only deleting files that are older than a certain number of days in any folder — here's how to do it. To delete files older than 30 days on Windows 10, use the “ForFiles” command. The command is: ForFiles /p “C:\path\to\folder” /s /d -30 /c “cmd /c del /q @file”.

Does Google Drive automatically delete photos?

On Files by Google, you can automatically delete backed-up photos to free up space. When you turn on Smart Storage, photos backed up in Google Photos are deleted automatically: If photos are saved for 60 days. If your device's storage is less than 25%

Does Google Drive delete files after inactivity?

When you have been inactive in Gmail, Google Drive (including Google Docs, Sheets, Slides, Drawings, Forms, Jamboard or Sites files) or Google Photos for 2 years, all of your content may be removed from that product.


1 Answers

based on another post by Tiziano Solignani and myself, here is a script that does the job... Please uncomment the setTrashed statement when you have it fully tested in the logger. Don't forget to change the email adress as well.

function DeleteMyJpegs() {
    var pageSize = 200;
    var files = null;
    var token = null;
    var i = null;
    var ThirtyDaysBeforeNow = new Date().getTime()-3600*1000*24*30 ;// 30 is the number of days 
//(3600 seconds = 1 hour, 1000 milliseconds = 1 second, 24 hours = 1 day and 30 days is the duration you wanted
    Logger.clear()

    do {
    var result = DocsList.getAllFilesForPaging(pageSize, token);
    var files = result.getFiles()
    var token = result.getToken();
        for(n=0;n<files.length;++n){
            if(files[n].getName().toLowerCase().match('.jpg')=='.jpg' && files[n].getDateCreated().getTime()<ThirtyDaysBeforeNow){
    //            files[n].setTrashed(true)
                Logger.log(files[n].getName()+' created on '+Utilities.formatDate(files[n].getDateCreated(), 'GMT','MMM-dd-yyyy'))
            }
          }    
     } while (files.length == pageSize);

      MailApp.sendEmail('[email protected]', 'Script AUTODELETE Jpegs report', Logger.getLog());

} 

EDIT : If you prefer to look at the size of the files in your drive, you could modify this do do some math on the jpg's size and other filetypes that take space) quite easily... and delete some files accordingly. This is a example to show how to handle the situation.

like image 178
Serge insas Avatar answered Sep 29 '22 23:09

Serge insas