1

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.

  • Can I ask you about the issue of your script shown in your question? – Tanaike Mar 11 at 23:49
  • @Tanaike Hi, I make a graph for explaining. There are no issues. I am not sure able to be like that or not. – jefferyear Mar 13 at 2:18
  • Thank you for replying and adding more information. I noticed that an answer has already been posted. I think that the answer will resolve your issue. – Tanaike Mar 13 at 7:04
2

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

  • This is code is right to work. But, I don't know why the source folder itself moved to the target folder, either. I just want its content to be moved to target folder. I am newbie about google script. Do you know about array in google script? I wonder an array for those content and iterating to the array. Then, make the array to the target folder. Do you know some good tutorials or reference material? Thanks your help. – jefferyear Mar 14 at 1:36
  • @jefferyear It's very likely that your coded passed the id of folder as sourceFileId so it was moved too. If you need further assistance please consider to post a new question including your adaptation of the above code. – Rubén Mar 14 at 2:16
  • Thanks. I add the notifications. – jefferyear Mar 14 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.