Search only files created by me in Google Drive

Asked

Viewed 71 times

1

Good morning

I am creating a script to delete files with more than 3 hours of creation in a folder in Google Drive, but there is a certain lock that you can only delete files created by you, so I need the script to search only those files created by me specifically

var files = folder.searchFiles('modifiedDate < "' + cutOffDate + '"');

I would like a help on how I could adjust this line of script (just above) so that it searches the file modification date and also Filtre only the files that were created by me

If it helps more, this is the complete script:

function getOldFileIDs() {
  // Old date is 3 Hours
  var oldDate = new Date().getTime() - 3600*1000*3;
  var cutOffDate = new Date(oldDate).toISOString();

  // Get folderID using the URL on google drive
  var folder = DriveApp.getFolderById('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
  var files = folder.searchFiles('modifiedDate < "' + cutOffDate + '"');

  var obj = [];
  while (files.hasNext()) {
    var file = files.next();
    obj.push({id: file.getId(), date: file.getDateCreated()});
  }
  obj.sort(function(x, y) {return x.date < y.date ? 1 : -1});
  obj.shift();
  var fileIDs = obj.map(function(e) {return e.id});
  return fileIDs;
};

function deleteFiles() {
  var fileIDs = getOldFileIDs();
  fileIDs.forEach(function(fileID) {
    Drive.Files.remove(fileID);
  });
};
  • in the searchfiles query there is only one " and '[email protected]' in Owners "

  • var files = folder.searchFiles('modifiedDate < "' + cutOffDate + '" and '[email protected]' in owners '); Would look like this @Lucasmiranda ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.