Google Script Move Folders

非 Y 不嫁゛ 提交于 2021-02-11 17:50:45

问题


I would like to move an entire folder including its subfolder to another folder using google script. I found this sample script on http://ctrlq.org/. However, the getfiles() method seems to limit to files under that folder. How can I solve this problem? Thanks in advance.

function moveFiles(source_folder, dest_folder) {
  
  var files = source_folder.getFiles();
 
  while (files.hasNext()) {
 
    var file = file.next();
    dest_folder.addFile(file);
    source_folder.removeFile(file);
 
  }
}

回答1:


there is no need to move files inside a folder that is being moved. when you move a folder, the files and folders inside will move with it.




回答2:


Get the files of root folder and again get all the subfolder then add up the list of files in root folder and its sub folders.

while (folders.hasNext()) {

var childfolder = folders.next();

var files = childfolder.getFiles();

while (files.hasNext())


来源:https://stackoverflow.com/questions/30240322/google-script-move-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!