Skip to content

Instantly share code, notes, and snippets.

@ttsukagoshi
Created December 30, 2019 14:45
Show Gist options
  • Save ttsukagoshi/c53f34cde0af81a4ca77fc6dc93f9695 to your computer and use it in GitHub Desktop.
Save ttsukagoshi/c53f34cde0af81a4ca77fc6dc93f9695 to your computer and use it in GitHub Desktop.
Google App Script (Javascript) to move all files in a particular Google Drive folder to another folder
/**
* Function to move all files in a particular Google Drive folder to another folder
* @param {string} moveFromFolderId - the original Google Drive folder ID from which you want to move the files
* @param {string} moveToFolderId - the Google Drive folder ID to which you want to move the files
*/
function moveAllFiles(moveFromFolderId, moveToFolderId) {
var moveFrom = DriveApp.getFolderById(moveFromFolderId);
var moveTo = DriveApp.getFolderById(moveToFolderId);
var files = moveFrom.getFiles();
while (files.hasNext()) {
var file = files.next();
moveTo.addFile(file);
moveFrom.removeFile(file);
}
}
// This one-by-one method takes too much time if you want to move a bulk of files at once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment