moving files between two folders in a shared drive - Cannot use this operation on a shared drive item

戏子无情 提交于 2021-02-04 08:09:20

问题


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.


回答1:


As @IMTheNachoMan points out this is a known issue, and I'm posting this answer with the link so that others who may face this issue, can go to the link and add a "star" next to the issue number for more visibility.

https://issuetracker.google.com/issues/76201003.



来源:https://stackoverflow.com/questions/62264447/moving-files-between-two-folders-in-a-shared-drive-cannot-use-this-operation-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!