Anyone know how create a Spreadsheet file in a specific folder on Google Drive?
I have already tried the answer from this link .
EDIT - Tried this answer :-D :
//"Move" file to folder-------------------------------//
var fileID = '12123123213321'
var folderID = '21321312312'
var file = DriveApp.getFileById(fileID).getName()
var folder = DriveApp.getFolderById(folderID)
var newFile = file.makeCopy(file, folder)
//Remove file from root folder--------------------------------//
DriveApp.getFileById(fileID).setTrashed(true)
But the "correct answer" gives me the follow error "Uncaught TypeError: Cannot find function makeCopy in object Spreadsheet."
I saw other answers but none of them work. I have already tried enable "Drive API" from "Advanced Google Services", but it's kind of complicate to work with.
UPDATE! Just to explain, my problem is that I was creating the Spreadsheet
var sheetId = SpreadsheetApp.create("filename").getId();
And then trying to makeCopy, or addFile in a folder. Something like that:
<someFolder>.addFile(sheet);
What I detect is that to work I have to get a File type, not a string like after. So I change to the code;
var sheetId = SpreadsheetApp.create("filename").getId();
var file = DriveApp.getFileById(sheet);
<someFolder>.addFile(file);
Instead of making a copy, why don't you just move it?
var file = DriveApp.getFileById(fileID),
folder = DriveApp.getFolderById(folderID),
parents = file.getParents();
folder.addFile(file);
while( parents.hasNext() )
parents.next().removeFile(file);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.