Skip to content

Instantly share code, notes, and snippets.

@FirePanther
Last active November 8, 2016 01:17
Show Gist options
  • Save FirePanther/8ec3094dfddc6573469bced9aa47a514 to your computer and use it in GitHub Desktop.
Save FirePanther/8ec3094dfddc6573469bced9aa47a514 to your computer and use it in GitHub Desktop.
Permanenty delete some Google Drive files from the trash. After I've watched the Videos in my YouTube folder I remove them but they still take much space in my Google Drive.
/**
* Permanenty delete some Google Drive files from the trash.
*/
function run() {
var trashed = DriveApp.getTrashedFiles();
while (trashed.hasNext()) {
parseTrashedFile(trashed.next());
}
}
/**
* Delete the file permanently if it is a YouTube video to save
* some space.
*/
function parseTrashedFile(file) {
// remove youtube files
if (file.getName().substr(-4) == '.mp4') {
if (getFullPath(file) == '/YouTube/') {
Drive.Files.remove(file.getId());
return true;
}
}
return false;
}
/**
* Get the full path of a file beginning and ending with a slash (/a/b/).
*/
function getFullPath(file) {
var path = '/',
parents = file.getParents();
while (parents.hasNext()) {
path = '/' + parents.next().getName() + path;
}
return path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment