0

I have a file by a specific name which it is not taking. Can you suggest? I want it to be a named file in the drive which should be moved to the folder. My Code :

function MoveFiles(){
var files = DriveApp.getFilesByName("Sampling Report-selected");
  while (files.hasNext()) {
    var file = files.next();
    var destination = DriveApp.getFolderById("1-dh-xfZZdfnMOlPasy_yoJBnnAsFsRIZ");
    destination.addFile(file);
    var pull = DriveApp.getRootFolder();
    pull.removeFile(file);
  
  }
}

Error: TypeError: DriveApp.getRootFolder(...).getFiles(...).getFilesByName is not a function

Please tell me to set up the trigger every time a new file is created. Because I only want it to be uploaded only when a new file is created.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • I cannot reproduce this behavior. I'm not getting any error when executing this. How are you executing this? Directly from the editor? Can you provide reproduction steps for this? – Iamblichus May 19 '21 at 08:51
  • (1) You don't need to put the line `var destination = DriveApp.getFolderById("...");` inside the loop. You can get the destination just once outside the loop, it will be faster. (2) And you can use the new `moveTo()` method instead of copy and remove: https://stackoverflow.com/a/63209081/14265469 – Yuri Khristich May 19 '21 at 10:09

0 Answers0