LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Sunday, February 21, 2021

GoogleドライブのファイルやフォルダをmoveTo(destination)で移動したい


moveTo(destination)というメソッドができていたので試してみました。

以下のメソッドは廃止されたようです。
 addFile(child) 
 addFolder(child) 
 removeFile(child)
 removeFolder(child) 

Deprecated methods
https://developers.google.com/apps-script/reference/drive/folder#deprecated-methods_1


ファイルを移動したい

コード.gs
function moveFile() {
  const fileId = "移動したいファイルID";
  const destinationFolderId = "移動先のフォルダID";
  
  const file = DriveApp.getFileById(fileId);
  const destinationFolder = DriveApp.getFolderById(destinationFolderId);
  
  file.moveTo(destinationFolder);
}


フォルダを移動したい

コード2.gs
function moveFolder() {
  const folderId = "移動したいフォルダのID";
  const destinationFolderId = "移動先のフォルダID";
  
  const folder = DriveApp.getFileById(folderId);
  const destinationFolder = DriveApp.getFolderById(destinationFolderId);
  
  folder.moveTo(destinationFolder);
}


参考

moveTo(destination) 

Deprecated methods

Release Notes
July 27, 2020

Latest post

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...