Does anyone know how to move a Google Drive folder to a different location using Google Apps Script?
Asked
Active
Viewed 225 times
1 Answers
0
You can make the content of one folder available inside another folder with the addFolder() method - the content will now be available inside the original folder as well as the target folder.
function moveFolder() {
var source = DriveApp.getFoldersByName("source").next();
var folder = DriveApp.getFoldersByName("target").next();
folder.addFolder(source);
}

Amit Agarwal
- 10,910
- 1
- 32
- 43
-
I know this method for moving a 'file' but will it work for moving a 'folder' and its contents (files and subfolders)??? – Mike Eburne Feb 03 '15 at 13:08
-
I have fixed the code. Also, if you wish to move the folder completely to another location, see [this link](http://ctrlq.org/code/19979-copy-folders-drive). You may call setTrashed(true) on the source folder to trash after copying. – Amit Agarwal Feb 03 '15 at 13:53
-
I have tried the code you pointed to in 'this link' above. However when I run it I get "TypeError: Test Folder 1111 is not a function, it is object. (line 45, file "MantisWorkflow"). – Mike Eburne Feb 03 '15 at 14:44
-
Sorry pressed CR too early... I have created a test source folder called '_Test Source Folder' and a target folder called '_Test Target Folder'. Inside the source folder is a sub-folder called 'Test Folder 111'. – Mike Eburne Feb 03 '15 at 14:46