Reputation: 273
I try to move a file from my root-folder into a defined folder. But my script send me the fautl: "Exception: The parameters (String) don't match the method signature for DriveApp.File.moveTo." - but why?
Does anyone has a tip for me?
function myMoveFile() {
var myFolderID = DriveApp.searchFolders("Title Contains 'Final_Folder'").next().getId();
var myNewDoc = DocumentApp.create("Doc per Script");
var myFileID = myNewDoc.getId();
DocumentApp.openById(myFileID).getBody().appendParagraph("TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT");
Logger.log(myFolderID);
DriveApp.getFileById(myFileID).moveTo(myFolderID);
}
Thanks
Upvotes: 0
Views: 150
Reputation: 201358
destination
of moveTo(destination)
is the folder object which is not the folder ID. I thought that this might be the reason for your issue. So how about the following modification?
function myMoveFile() {
var myFolder = DriveApp.searchFolders("Title Contains 'Final_Folder'").next();
var myNewDoc = DocumentApp.create("Doc per Script");
var myFileID = myNewDoc.getId();
DocumentApp.openById(myFileID).getBody().appendParagraph("TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT");
Logger.log(myFolder.getId());
DriveApp.getFileById(myFileID).moveTo(myFolder);
}
About the following 2nd question,
My intention is to create a file via GScript and then move it to a defined folder (e.g. "Final_Folder"). There are 2 folders with the same name that I want to move I avoid that the file is moved to the wrong folder.
In this case, as a workaround, how about using the star? At Google Drive, a star can be added to the files and folders. In your situation, when the same folders are existing and you want to move the file to one of those folders, please add a star to the specific folder you want to use. I thought that this might be a workaround for identifying the specific folder from the same folder name.
Before you run this script, please add a star to the folder you want to use. And, run this script. By this, the file is moved to the starred folder. By this, you can use the specific folder from the same folder names.
function myMoveFile() {
var folders = DriveApp.searchFolders("Title Contains 'Final_Folder'");
while (folders.hasNext()) {
var myFolder = folders.next();
if (myFolder.isStarred()) {
var myNewDoc = DocumentApp.create("Doc per Script");
var myFileID = myNewDoc.getId();
DocumentApp.openById(myFileID).getBody().appendParagraph("TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT");
Logger.log(myFolder.getId());
DriveApp.getFileById(myFileID).moveTo(myFolder);
break;
}
}
}
Upvotes: 1