Reputation: 171
I'm trying to make my google docs script create a backup copy of the file each time I open it.
To make a copy I write
var name = File.getName();
var filecopy = File.makeCopy(name + " backup");
But it won't recognize the File class. Although it knows DocsList. How do I make it work or make a copy of the file another way?
Upvotes: 0
Views: 773
Reputation: 8660
GAS permits to call class methods or instance only native classes (Object
, String
, etc), own classes or Google Services (DocList
, SpreadsheetApp
, etc). Other classes like File
, Folder
, Spreadsheet
, Range
, etc are accessible and instanceable only via calling the services functions, for example, DocsList.getFileById("...");
returns the File
class instance.
The following function copies a file having the srcFileID
ID to a new file with the name stored in the dstFileName
parameter.
function testCopy(srcFileID, dstFileName) {
var srcFile = DocsList.getFileById(srcFileID);
srcFile.makeCopy(dstFileName);
}
Upvotes: 1
Reputation: 7957
You cannot use the File class that way. Use something on these lines
var file = DocsList.getFileById(ID) ; // you can use DocsList.find or DocsList.create
var filecopy = file.makeCopy();
Upvotes: 0