How to make a Google Drive script to delete all subfolders and files with folder ID?

Google Drive has a problem: if you open the top-level folder, everything in the folder is still in use ... I'm not sure how such a big mistake could survive, but it ... more details here:

http://productforums.google.com/forum/#!topic/drive/p3LZQnRNB24

I don’t want to manually go through and parse everything manually, so I think I can create a script that I could just plug in the folder identifier and do all the work.

How to do it?

+4
source share
3 answers

it does not display any of each folder and file on your drive.

// create a Google Document
// Tools / Script Editor
// paste this in
// update line 13 and save
// hit play to run. you may have to run several times as the script will die after 5 or 6 minutes.

function findSharedFolders() {
  // https://developers.google.com/apps-script/reference/drive/drive-app
  // https://developers.google.com/drive/web/search-parameters
  // http://stackoverflow.com/questions/21227771/how-do-i-script-google-drive-to-unshare-all-subfolders-and-files-given-a-folder
  // https://productforums.google.com/forum/#!topic/drive/p3LZQnRNB24

  var email = "unwanted-address@gmail.com"; // <<<<< INSERT THE UNDESIRED EMAIL ADDRESS HERE

  var body = DocumentApp.getActiveDocument().getBody();
  body.appendParagraph(email).setHeading(DocumentApp.ParagraphHeading.HEADING1);
  var folders = DriveApp.searchFolders("'"+email+"' in writers");  while (folders.hasNext()) unshare_(folders.next(), body, email);
  var files   = DriveApp.searchFiles(  "'"+email+"' in writers");  while (  files.hasNext()) unshare_(  files.next(), body, email);
}

function unshare_(file, body, email) {
// Logger.log(file.getName());
   var para = body.appendParagraph(file.getName());
   try { file.removeEditor(email); }
   catch (e) { para.setLinkUrl(file.getUrl()); para.appendText(" (" + e + ")"); }
}
+3
source

, .

http://i.imgur.com/fbJr6eG.png

, .

// Google/// Script // // 13 // . , , , Script 5 6 .

function findSharedFolders() {// https://developers.google.com/apps-script/reference/drive/drive-app
//https://developers.google.com/drive/web/search-parameters// Script Google , ?//https://productforums.google.com/forum/#!topic/drive/p3LZQnRNB24

var email = "unwanted-address@gmail.com"; // < < < <

var body = DocumentApp.getActiveDocument(). getBody();
body.appendParagraph( ).setHeading(DocumentApp.ParagraphHeading.HEADING1); var folders = DriveApp.searchFolders( "'" + email + "' ); (folders.hasNext()) unshare_ (folders.next(), body, email); var = DriveApp.searchFiles( "'" + email + "' ); while (files.hasNext()) unshare_ (files.next(), body, email); }

unshare_ (, , ) {//Logger.log(file.getName()); var para = body.appendParagraph(file.getName()); { file.removeEditor( ); } catch (e) { para.setLinkUrl(file.getUrl()); para.appendText( "(" + e + ")" ); }}

0

, , google ( ).

script, :

// create a Google Document
// Tools / Script Editor
// paste this in
// update line 13 and save
// hit play to run. you may have to run several times as the script will die after 5 or 6 minutes.

function findSharedFolders() {
  // https://developers.google.com/apps-script/reference/drive/drive-app
  // https://developers.google.com/drive/web/search-parameters
  // http://stackoverflow.com/questions/21227771/how-do-i-script-google-drive-to-unshare-all-subfolders-and-files-given-a-folder
  // https://productforums.google.com/forum/#!topic/drive/p3LZQnRNB24

  var email = "unwanted-address@gmail.com"; // <<<<< INSERT THE UNDESIRED EMAIL ADDRESS HERE

  var folders = DriveApp.searchFolders("'"+email+"' in writers");  while (folders.hasNext()) unshare_(folders.next(), email);
  var files   = DriveApp.searchFiles(  "'"+email+"' in writers");  while (  files.hasNext()) unshare_(  files.next(), email);
}

function unshare_(file, email) {
// Logger.log(file.getName());
   try { file.removeEditor(email); }
   catch (e) {  }
}
0

All Articles