LoginSignup
0
1

More than 1 year has passed since last update.

40 代おっさん GASのFolderクラスについて学ぶ

Posted at

本記事ついて

本記事は プログラミング初学者の私が学習していく中でわからない単語や概要をなるべくわかりやすい様にまとめたものです。
もし誤りなどありましたらコメントにてお知らせいただけるとありがたいです。

Folderクラス

Folderクラスとは
フォルダを操作する機能を提供するクラス

*Folderクラスの主なメンバーの図は、参考資料の本を見ていただくか、ネットで調べください。

ちなみにこちらで書いてありました。
https://excel-ubara.com/apps_script1/GAS036.html

お試し

function tosiki() {
  const id     = '××××××××××××××××××××××';
  const folder = DriveApp.getFolderById(id);

  console.log(folder.getId());
  console.log(folder.getUrl());
  console.log(folder.getName());
  console.log(folder.getDescription());

  console.log(folder.getDateCreated());
  console.log(folder.getLastUpdated());

  console.log(folder.isStarred());
  console.log(folder.isTrashed());
}

ファルダやファイルの作成

FolderオブジェクトにたいしてcreateFolderメソッド、createFileメソッドを実行することで、追加、作成が可能

フォルダ

構文

Folderオブジェクト.createFolder(ファルダ名)

お試し

function tosiki() {
  const id     = '1BxF2vAvoSvfc9mEpaOIt6mPT37BMeHSV';
  const folder = DriveApp.getFolderById(id);

  for (let i = 1; i <= 3; i++) {
    const name = String(i).padStart(2, '0');
    folder.createFolder(name);
  }
}

ファイル

構文

Folderオブジェクト.createFile(ファイル名, 内容, [, MIMEタイプ])

お試し

function tosiki() {
  const id     = '***************';
  const folder = DriveApp.getFolderById(id);

  const name = 'tosiki.txt';
  const content = '利樹君です!';
  folder.createFile(name, content, MimeType.PLAIN_TEXT);
  
  const targetId = '******************';
  folder.createShortcut(targetId);
}

参考資料

https://www.amazon.co.jp/%E8%A9%B3%E8%A7%A3-Google-Apps-Script%E5%AE%8C%E5%85%A8%E5%85%A5%E9%96%80-%E7%AC%AC3%E7%89%88/dp/4798064742

0
1
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
1