概要
特定のGoogleドライブのフォルダ内にあるファイル名とURLをGoogle Apps Scriptで一括取得する。
類似の記事はあるが、数年前のもの・複雑なものが多いため投稿。
Apps Scrip
- 一覧をエクスポートするスプレッドシートのIDを記載
function getfileinfo() {
const files = DriveApp.getFolderById("ここにスプレッドシートのIDを記載").getFiles()
- 取得する情報の選択とスプレッドシートへのエクスポート
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)
}