I have a Spreadsheet in a folder in google Drive, let's call the folder "FolderX"
I opened AppScript in the Spreadsheet and wrote this function:
function myFunction() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet1');
const ss_id = ss.getId();
const file = DriveApp.getFileById(ss_id);
const parent_folders = file.getParents()
const folder_name = parent_folders.next().getName(); //desired result
sh.getRange('A1').setValue(folder_name);
}
This is an expected behavior stated in the
Another Reference: I just tweaked the code a bit to set the value on the currently selected cell.
Using Button:
CodePudding user response:
function getFolder() {
const ss = SpreadsheetApp.getActive();//Logger outputs the name of this spreadsheet folder
const id = ss.getId();
const file = DriveApp.getFileById(id);
const f = file.getParents().next()
Logger.log(f.getName())
}