0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Googleドライブフォルダ内のファイル名とURLをGoogle Apps Scriptで一括で取得する

Posted at

概要

特定のGoogleドライブのフォルダ内にあるファイル名とURLをGoogle Apps Scriptで一括取得する。
類似の記事はあるが、数年前のもの・複雑なものが多いため投稿。

Apps Scrip

  1. 一覧をエクスポートするスプレッドシートのIDを記載
function getfileinfo() {

  const files = DriveApp.getFolderById("ここにスプレッドシートのIDを記載").getFiles()

※スプレッドシートのID取得方法
画像のURLの赤い部分
無題.png

  1. 取得する情報の選択とスプレッドシートへのエクスポート
 const files = DriveApp.getFolderById("ここにスプレッドシートのIDを記載").getFiles()

  let filinfo = [] 

  while (files.hasNext()) {
    let buf = files.next()
    filinfo.push([

      buf.getName(),
      buf.getLastUpdated(),
      buf.getUrl()

    ])
  }
  console.log(filinfo)
  console.log(filinfo.length)
  console.log(filinfo[0].length)

  const ss = SpreadsheetApp.getActiveSheet()
  ss.getRange(2,2,filinfo.length,filinfo[0].length).setValues(filinfo)

コピペ用

function getfileinfo() {

  const files = DriveApp.getFolderById("ここにスプレッドシートのIDを記載").getFiles()

  let filinfo = []  //ファイル情報

  while (files.hasNext()) {
    let buf = files.next()
    filinfo.push([

      buf.getName(),
      buf.getLastUpdated(),
      buf.getUrl()

    ])
  }
  console.log(filinfo)
  console.log(filinfo.length)
  console.log(filinfo[0].length)

  const ss = SpreadsheetApp.getActiveSheet()
  ss.getRange(2,2,filinfo.length,filinfo[0].length).setValues(filinfo)

}

スクリプトの定期実行

Apps Scriptのトリガー設定を使用。
画像を参考に任意の時間を設定する。
ファイル取得 - プロジェクトのトリガー - Apps Script - Google Chrome 2023_02_09 23_21_49.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?