Move File to a Specific Folder using Google Apps Script (2)

PHOTO EMBED

Mon Jun 27 2022 16:52:01 GMT+0000 (Coordinated Universal Time)

Saved by @Waydes #javascript

/*
    Move file to another Google Drive Folder
    Arguments:
       - fileID: id of file to be moved
       - destFolderID: id of the folder to which the file will be moved
    Source: https://www.labnol.org/code/20201-move-file-to-another-folder
  */
function moveFileToAnotherFolder(fileID, destFolderID) {
  var file = DriveApp.getFileById(fileID);
 
  // Remove the file from all parent folders
  var parents = file.getParents();
  while (parents.hasNext()) {
    var parent = parents.next();
    parent.removeFile(file);
  }
 
  DriveApp.getFolderById(destFolderID).addFile(file);
}
content_copyCOPY

https://www.labnol.org/code/20201-move-file-to-another-folder