複数ファイルを一気に移動したくて作ったアプリです
移動するファイルを1行ずつ「File URLs」テキストエリアに入れて
移動先のフォルダのURLを「Folder URL」に入れて
Submitをクリックする
Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
function moveFiles(fileIds, folderId) {
const destinationFolder = DriveApp.getFolderById(folderId);
fileIds.forEach(fileId => {
const file = DriveApp.getFileById(fileId);
file.moveTo(destinationFolder);
});
return "All files moved successfully!";
}
index.html
<!DOCTYPE html>
<html>
<body>
<a target="_blank" href="https://script.google.com/home/projects/SCRIPT_ID/edit">SCRIPT</a>
<div>
<label for="fileUrls">File URLs (one per line):</label>
<br>
<textarea id="fileUrls" rows="5" cols="50"></textarea>
</div>
<div>
<label for="folderUrl">Folder URL:</label>
<br>
<input type="text" id="folderUrl">
</div>
<button id="submit">Submit</button>
<script>
document.getElementById("submit").onclick = function() {
const fileUrls = document.getElementById("fileUrls").value;
const folderUrl = document.getElementById("folderUrl").value;
// 改行で区切ってfileIdsを取得
const fileIds = fileUrls.split('\n').map(url => url.trim().split("/d/")[1].split("/")[0]);
const folderId = folderUrl.split("/folders/")[1];
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(onSuccess)
.moveFiles(fileIds, folderId);
};
function onSuccess(result) {
alert(result);
}
function onFailure(e) {
alert([e.message, e.stack]);
}
</script>
</body>
</html>
Tips
アプリ内からスクリプトエディタを開けるようにAppsScriptプロジェクトのリンクを配置しています
<a target="_blank" href="https://script.google.com/home/projects/SCRIPT_ID/edit">SCRIPT</a>
関連記事