本記事ついて
本記事は プログラミング初学者の私が学習していく中でわからない単語や概要をなるべくわかりやすい様にまとめたものです。
もし誤りなどありましたらコメントにてお知らせいただけるとありがたいです。
Fileクラス
Fileクラスとは
ファイルを操作する機能を提供するクラス
*Fileクラスの主なメンバーの図は、参考資料の本を見ていただくか、ネットで調べください。
ちなみにこちらで書いてありました。
https://excel-ubara.com/apps_script1/GAS036.html
お試し
function tosiki() {
const id = '****************';
const file = DriveApp.getFileById(id);
console.log(file.getId());
console.log(file.getName());
console.log(file.getDescription());
console.log(file.getMimeType());
console.log(file.getSize());
console.log(file.getSize());
console.log(file.getUrl());
console.log(file.getDownloadUrl());
console.log(file.getDateCreated());
console.log(file.getLastUpdated());
console.log(file.isStarred());
console.log(file.isTrashed());
}
ファイルのコピー・移動・削除
ファイル移動
moveToメソッドを使用
構文
Fileオブジェクト.moveTo(フォルダ)
ファイルをゴミ箱に移動
setTrashedメソッドを使用
構文
Fileオブジェクト.setTrashed(真偽値)
お試し
function tosiki() {
const id = '**********************';
const file = DriveApp.getFileById(id);
const movedFile = file.makeCopy('tosiki.txt');
const destinationId = '1XzpL7AEzOCRunIc4NCI60MTFbWbWpaFM';
const destination = DriveApp.getFolderById(destinationId);
movedFile.moveTo(destination);
const trasheFile = file.makeCopy('tosiki.txt');
trasheFile.setTrashed(true);
}