Move google drive folder with all files/folders in it from one directory to another based on google sheet value

140 Views Asked by At

I want the folders with all the files or subfolders in them to be moved from one directory/folder to another based on the value in google sheet, but at the same time not change the Id of the folder because the folder is shared with other team members, therefore, don't want to mess with access. I have searched through all the net. what I found was the script that creates the copy of the folder (that definitely changes the ID) and removes the old folder, which may definitely change the access status. The folder url lies in the sheet that should be moved through directories. Here is the code that may help for better understanding.

function onEdit(e) { 
 const inactive_folder = DriveApp.getFileById('1_hBkktH0Alzx06XS0Hu2tI0MSQ_SffKw');
 const active_folder = DriveApp.getFolderById('13uon5guBduiA0gCKiLjl9ElOgek9CiU6');

 if (e.range.columnStart != 1 || e.value != "Inactive"){
  const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,13).getValues();
  // Url of the client folder in 11th column 
  let client_folder = rData[0][11];

  DriveApp.getFileById(client_folder).moveTo(inactive_folder);
 } else {
  DriveApp.getFileById(client_folder).moveTo(active_folder);
 }
}

Any help will be highly appreciated.

0

There are 0 best solutions below