GAS searchFiles使用時にエラー「Exception: Invalid argument: q」が発生した場合の対処法
- 作成日 2022.09.10
- 更新日 2022.11.07
- Google Apps Script
- Google Apps Script
GAS(Google Apps Script)で、searchFiles使用時にエラー「Exception: Invalid argument: q」が発生した場合の対処法を記述してます。存在しない日付などを設定している場合に発生します。
環境
- OS windows11 home
- ブラウザ chrome 107.0.5304.88
エラー全文
以下のコードを、実行時に発生
function myFunction() {
const query = 'modifiedDate >= "2022-09-01" and modifiedDate <= "2022-11-31"';
const files = DriveApp.searchFiles(query);
while (files.hasNext()) {
const file = files.next();
Logger.log(`ファイル名${file.getName()}`);
}
}
エラー全文
Exception: Invalid argument: q
myFunction @ コード.gs:7
画像
原因
存在しない日付( 11月31日 )を指定しているため
対処法
存在する日付を指定する
function myFunction() {
const query = 'modifiedDate >= "2022-09-01" and modifiedDate <= "2022-11-30"'
const files = DriveApp.searchFiles(query);
while (files.hasNext()) {
const file = files.next();
Logger.log(`ファイル名${file.getName()}`);
}
}
-
前の記事
Linux ディレクトリ内のファイルの行数を一覧表示する 2022.09.10
-
次の記事
GAS スプレッドシートでセルの値をクリアにする 2022.09.10
コメントを書く