Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...