I was wondering if someone could take a look at this for me.
My company has a ton of client folders on google drive that are full of content (files and folders). I'm trying to take all of the existing content, and move it into a newly created folder within each client folder named "old client work".
When I run the code, there's an issue with moving folders. Creating the "old client work" folder works fine, as does moving existing files into it. But the code runs into an error when trying to move folders.
Here is the code I have:
function createOldClientWorkFolder() {
var clientContentFolder = DriveApp.getFolderById("IDhere");
var clientFolders = clientContentFolder.getFolders();
while(clientFolders.hasNext()) {
var client = clientFolders.next();
var oldWorkFolder = client.createFolder('Old Client Work');
var clientContentFiles = client.getFiles();
var clientContentFolders = client.getFolders();
while (clientContentFiles.hasNext()) {
var fileToMove = clientContentFiles.next();
fileToMove.moveTo(oldWorkFolder)
}
while (clientContentFolders.hasNext()) {
var folderToMove = clientContentFolders.next();
folderToMove.moveTo(oldWorkFolder)
}
}
}
Any help would be appreciated!
(Since you haven't provided a log/error message I'm guessing here, but I encountered something similar a while ago while trying to move folders so I thought this might help.)
moveTo requires that you have permission to the object that you're trying to move itself. Could there be a possibility that your app script doesn't have the write permission to the actual client folder? (moveTo modifies the parent property of the folder object you're trying to move, so you also read write permission, not just read).