GAS googleドライブの指定したidのフォルダを取得する
- 作成日 2023.01.04
- Google Apps Script
- Google Apps Script
GAS(Google Apps Script)で、googleドライブの指定したidのフォルダを取得する手順を記述してます。ここでは実際に「id」でフォルダを取得してフォルダ名を確認します。
環境
- OS windows11 home
- ブラウザ chrome 108.0.5359.125
指定したidのフォルダを取得
指定したidのフォルダを取得するには、「DriveApp.getFolderById()」を使用します。
DriveApp.getFolderById(id)
フォルダidは、フォルダを開いたリンクから確認可能です。
実際に、id名を指定して、そこからフォルダ名を取得してみます。
function myFunction() {
// idから取得
const folder = DriveApp.getFolderById('1wFZgGSjKoE5wX4Wsxxxxxxxxxxx');
// フォルダ名を取得
console.log(folder.getName());
}
フォルダ名が取得されていることが確認できます。
存在しないidを指定
存在しないidを指定すると、エラーが発生します。
function myFunction() {
// idから取得
const folder = DriveApp.getFolderById('xxxxxxxxxxxxxxxxxxxxx');
// フォルダ名を取得
console.log(folder.getName());
}
-
前の記事
javascript animateを逆に再生させる 2023.01.04
-
次の記事
Dart リスト(配列)の最後の値を取得する 2023.01.04
コメントを書く