0

I've just created a copy of a file with a new name using this command:

file.makeCopy(''+newfilename+'');  

How can I find the ID of the new file?

Marios
  • 26,333
  • 8
  • 32
  • 52

3 Answers3

1

If you check the official documentation, you will see that makeCopy() returns an object of the class File.

The latter has a method getId() which gives you the id of the File.

const newFile = file.makeCopy('newfilename'); // it returns an object of type File
const newFileID = newFile.getId(); // File has a method .getId()
Marios
  • 26,333
  • 8
  • 32
  • 52
  • Sorry to be dense, but I'm not a professional coder. This is what I've just done: file.makeCopy(''+newfilename+''); const newFile=file.makeCopy(''+newfilename+''); const newFileID = newFile.getId() file.makeCopy(''+newfilename+''); I can intuit that this was not what you had in mind but am not sure how to connect my creation of the file with the getID() in this case. – Kenton Sparks Oct 13 '20 at 14:23
0

Just use:

SpreadsheetApp.getActiveSpreadsheet().getId()
Doom
  • 206
  • 1
  • 4
  • 14
0

Use the following

var copy = file.makeCopy('Put the new file name here');
var id = copy.getId();

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166