I have a Google Apps Script that I want to have check a folder (and all subfolders) and set to trashed all files of a certain file type. (in my case Google Doc format files).
I'm certain my problem is with my var filetype or my If statement line. Tried several variations and searched the internet but not finding the answer that helps me.
function trashit() {
var sourcefolder=DriveApp.getFolderById('source folder ID here'); //My Drive folder to take the files from.
var files=sourcefolder.getFiles();
supportsTeamDrives: true;
while(files.hasNext()) { //contintue while statement until all files are run.
var file=files.next();
var filetype=DriveApp.getFilesByType(MimeType.GOOGLE_DOCS);
if (filetype == "GOOGLE_DOCS") { //code does this IF statement when the file type matches
supportsTeamDrives: true;
supportTeamDrives: true;
file.setTrashed(true);
};
}
}
I want this code to check the folder, and set/move to the trash all files of the specified file type. Any help with this would be appreciated.
Try this:
function trashit() {
var sourcefolder=DriveApp.getFolderById('ID');
var files=sourcefolder.getFilesByType(MimeType.GOOGLE_DOCS);
while(files.hasNext()) {
var file=files.next();
file.setTrashed(true);
}
}
I don't believe supportsTeamDrives: true;
is used in DriveApp. I believe it is an option in the Advanced Drive API. You should consider taking @webstermath 's advice.