GAS googleドライブ内で今日更新されたファイルを抽出する

GAS googleドライブ内で今日更新されたファイルを抽出する

GAS(Google Apps Script)で、googleドライブ内で今日更新されたファイルを抽出する手順を記述してます。「searchFiles」に現在日付を条件にすることで可能です。

環境

  • OS windows11 home
  • ブラウザ chrome 108.0.5359.125

今日更新されたファイルを抽出

今日更新されたファイルを抽出するには、「searchFiles」を使用します。

// 本日の日付を yyyy-mm-dd で取得して条件に適応
const query = `modifiedDate >= '${Utilities.formatDate(new Date(), "JST", "yyyy-MM-dd")}'`;

const files = DriveApp.searchFiles(query);

実際に、取得するコードは以下となります。

function myFunction() {

  const query = `modifiedDate >= '${Utilities.formatDate(new Date(), "JST", "yyyy-MM-dd")}'`;

  const files = DriveApp.searchFiles(query);

  while (files.hasNext()) {
    const file = files.next();
    Logger.log(`ファイル名 : ${file.getName()} 更新日時 : ${file.getLastUpdated()}`);
  }

}

実行結果