Charles Hsu
Charles Hsu

Reputation: 21

How to get the current folder where code file located, using Google App Script?

as Title.

I utilized Google App Script to copy an existing spreadsheet to a new one. It was created at the root directory. How can I create a spreadsheet at the current folder where the code file located?

Thanks!

Upvotes: 0

Views: 770

Answers (1)

user3075569
user3075569

Reputation:

If you're using the makeCopy() method, you can pass the destination directory where you want the file to be created:

function leFunction(){

 var spreadsheet = SpreadsheetApp.openById('spreadsheetId'); 
 var destFolder = DriveApp.getFolderById('FolderId'); 
 DriveApp.getFileById(spreadsheet.getId()).makeCopy(destFolder); 

}

Upvotes: 2

Related Questions