Skip to content

Instantly share code, notes, and snippets.

@mr-nit
Forked from wchiquito/gist:5932870
Last active April 27, 2023 03:50
Show Gist options
  • Select an option

  • Save mr-nit/f0001bc5750dc74ddd14626aca708d02 to your computer and use it in GitHub Desktop.

Select an option

Save mr-nit/f0001bc5750dc74ddd14626aca708d02 to your computer and use it in GitHub Desktop.
[Google Apps Script] Move files
/* CODE FOR DEMONSTRATION PURPOSES */
function getFileById_(idFile) {
return DocsList.getFileById(idFile);
}
function getFolderById_(idFolder) {
return DocsList.getFolderById(idFolder);
}
function copyFile_(file) {
return file.makeCopy(file.getName() + '_Copy');
}
function moveFile_(file, addToFolder, removeFromFolder) {
file.addToFolder(addToFolder);
file.removeFromFolder(removeFromFolder);
}
function main() {
var _folderTarget = getFolderById_('[ID FOLDER TARGET]');
var _file = getFileById_('[ID FILE TO COPY]');
var _copyFile = copyFile_(_file);
var _folderSource = _copyFile.getParents()[0];
moveFile_(_copyFile, _folderTarget, _folderSource);
}
/* CODE FOR DEMONSTRATION PURPOSES */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment