Google-apps-script – Is google app script able to move a specific folder to the other one on google drive on time or condition triggering

google-apps-scriptgoogle-drive

I refer a article to do what I want to move a specific folder to the other one. (The reference article is on the bottom.)

Is it possible to move just the content only?

I made it. But, it also moves the parent folder to the target folder.

It seems to have a command line tool. (I post the reference on the bottom.) Is it able to make it?

function moveFolderToFolder() {
  var targetFolder = DriveApp.getFolderById("theencryptedtargetid");
  var sourceFolder = DriveApp.getFolderById("theencryptedsourceid");
  var currentFolders = sourceFolder.getParents();
  while (currentFolders.hasNext()) {
    var currentFolder = currentFolders.next();
    currentFolder.removeFolder(sourceFolder);
  }
  targetFolder.addFolder(sourceFolder);
};

About the google app script to move the folder to the other one.

https://stackoverflow.com/questions/18393932/implement-a-folder-move-function-in-google-dirve

About the command line tool:

Move large folder from personal Google Drive to a Team Drive

EDIT:
I make a hierarchical graph.
—————————————————
(Before)
——My Google Drive Root
    —sourcefolder
    —targetfolder
(After)
——My Google Drive Root
    —targetfolder
    —sourcefolder

The entire “sourcefolder” had been moved to “targetfolder”.

However, I just want its content to be moved to “targetfolder”.

The content of “sourcefolder” is as below.

——sourcefolder
         —folderone
         —foldertwo
         —file1.txt
         —file2.txt

What I want that as below.

(Expected)
——My Google Drive Root
    —targetfolder
         —folderone
         —foldertwo
         —file1.txt
         —file2.txt

EDIT:
Make a notification for further clearly explaining.
The source folder itself is not to be moved to target folder. Only the content of source folder-“folderone”, “foldertwo”, “file1.txt” and “file2.txe” as the graph showing are to be moved to target folder.

Best Answer

Yes it's possible. Your script should iterate over the content to move. From this answer to Moving Files In Google Drive Using Google Script:

function moveFiles(sourceFileId, targetFolderId) {
  var file = DriveApp.getFileById(sourceFileId);
  file.getParents().next().removeFile(file);
  DriveApp.getFolderById(targetFolderId).addFile(file);
}

Related