This code make a copy of the given file, gives it a new name and moves it to destination.
DriveApp.getFileById(fileId).makeCopy(fileName,fileDestination)
How can I have the same function when I have all my files on Shared Drive? I have activated the Drive API and everything works fine except the code above!
CodePudding user response:
Try using this code instead:
function copytoMyDrive(){
var destinationMyDriveId = "yourdestinationfolderid in my Drive";
var sheet = "your sheet ID";
Drive.Files.copy({title:'Copy of file',parents:[{id:destinationMyDriveId}]},sheet, {supportsAllDrives: true})
}
The title parameter is optional if you want the copied file to have a different name. After running the code you should have a copy of the file that was in your shared Drive on your specified folder in My Drive.
Reference: