Move files automatically from one folder to another in Google Drive

僤鯓⒐⒋嵵緔 提交于 2019-12-12 01:54:34

问题


Problem:

Files get pulled automatically from my emails to a folder on my Google Drive. The files are automatically given a name, which was the subject of the email, e.g. "Beach". Multiple files can thus have the same name if emails have the same subject name.

Once the files have landed in Google Drive, I want to move the files, say the ones called "Beach", to another folder called "Beach".

What is the best way to do this? I have tried using scripts, lists of folders/ID/file names etc in spreadsheets, yet can't quite get it.


回答1:


According to this article, you can use Google Apps Scripts to move files across folders.

function moveFiles(source_folder, dest_folder) {

  var files = source_folder.getFiles();

  while (files.hasNext()) {

    var file = files.next();
    dest_folder.addFile(file);
    source_folder.removeFile(file);

  }
}

Here are some related threads which might help:

  • Google Drive: Move file to folder
  • SCRIPT TO MOVE FILES FROM MYDRIVE TO ANOTHER FOLDER IN GOOGLE DRIVE



回答2:


This is what I use and it works well The_unique_File_id is the part after drive.google.com/drive/folders/ the letters and numbers

function copyFiles(source_folder, dest_folder) {

  var source_folder = DriveApp.getFolderById('The_unique_File_id'); 
  var dest_folder = DriveApp.getFolderById('The_unique_File_id'); 
  var files = source_folder.getFiles();

  while (files.hasNext()) {

    var file = files.next();
    dest_folder.addFile(file);
    source_folder.removeFile(file);

  }
}


来源:https://stackoverflow.com/questions/40663814/move-files-automatically-from-one-folder-to-another-in-google-drive

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