Help us understand the problem. What is going on with this article?

指定フォルダ内のファイル一覧を取得する

More than 1 year has passed since last update.

概要

Googleドライブの写真フォルダから各フォルダの写真名をスプレッドシートに出力する。

フォルダ構成
写真フォルダ
 ├ xxxx年xx月xx日フォルダ
 │ ├ 写真A
 │ └ 写真B
 ├ xxxx年xx月xx日フォルダ
 │ ├ 写真A
 │ └ 写真B
 └ xxxx年xx月xx日フォルダ
   ├ 写真A
   └ 写真B
file.gs
/*
 * 指定シートにフォルダ内のファイル情報を出力する。
 */
function main() {  
  // 出力するシート名
  var FOLDER_ID = 'フォルダID';
  // 出力するシート名
  var SHEET_NAME = 'シート名';

  // フォルダ内のフォルダを取得
  var folders = DriveApp.getFolderById(FOLDER_ID).getFolders();
  // 指定したシート名に出力する
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME).clear();

  if (folders.hasNext()) {
    var index = 0;
    var values = [];
    while(folders.hasNext()) {
      var folder = folders.next();
      // フォルダ名
      var folderName = folder.getName();
      // フォルダURL
      var folderUrl = folder.getUrl();

      var files = folder.getFiles();
      while(files.hasNext()) {
        var file = files.next();
        // ファイル名
        var fileName = file.getName();
        // ファイルダウンロードURL
        var fileDownloadUrl = file.getDownloadUrl();
        values[index] = [index + 1, folderName, folderUrl, fileName, fileDownloadUrl];
        index++;
      }
    }
    sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
  }
}
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away