如何找到当前脚本文件所在文件夹的路径? [英] How do I locate the path of the folder in which the current script file is located?

查看:300
本文介绍了如何找到当前脚本文件所在文件夹的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到当前文件夹的路径?我只想要能够获取文件夹的路径,以便我可以操作文件夹中的文件而无需在脚本中键入路径。

How do I locate the path of the current folder? I just want to be able to get the path of the folder so that I can manipulate the files in the folder without typing the path into the scripts.

推荐答案

对于电子表格,我发现它可以正常工作:

For a Spreadsheet I found this to work:

thisFileId = SpreadsheetApp.getActive().getId();
var thisFile = DriveApp.getFileById(thisFileId);
var parentFolder = thisFile.getParents()[0].getName();

这篇关于如何找到当前脚本文件所在文件夹的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆