I have code to move files from one folder to another. It does not work on two folders in the **same shared drive*. I get the following error:
Exception: Cannot use this operation on a shared drive item.
function moveFilesFromFolderToFolder(sourceFolderID, destinationFolderID)
{
var sourceFolder = DriveApp.getFolderById(sourceFolderID);
var destinationFolder = DriveApp.getFolderById(destinationFolderID);
var sourceFiles = sourceFolder.getFiles();
while(sourceFiles.hasNext())
{
var file = sourceFiles.next();
destinationFolder.addFile(file);
sourceFolder.removeFile(file);
}
}
I know I can make a copy in the destination folder but I don't want to do that. I'm not sure why I can't move files between folders in the same shared drive. Very strange...
DriveApp.getFolders()
returns folders from Shared Drives so DriveApp
does work on Shared Drives.
https://developers.google.com/apps-script/reference/drive/permission has references to shared drives.
Nowhere does the DriveApp documentation say it does not work on Shared Drives. So it doesn't make sense that DriveApp wouldn't work on Shared Drives. I can do almost everything else with it on shared drives, like create folders, copy files, etc. So why would I not be able to do this one thing.
I am pretty sure this is a bug but wanted to check here if I am missing something obvious.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…