I use this Apps Script to make backup copies of some files:
var sourceFolderId = "xxxxxx";
var sourceFolder = DriveApp.getFolderById(sourceFolderId);
var latestFiles = sourceFolder.getFiles();
var backupFolderId = "yyyyyy";
var backupFolder = DriveApp.getFolderById(backupFolderId);
while(latestFiles.hasNext()) {
var file = latestFiles.next();
file.makeCopy(backupFolder);
}
It works fine - copying all files from the source folder to the backup folder- except that if any file being copied is a "Google Apps script" file it doesn't copy it to the backup folder, it copies it to "My Drive".
I then have to move it from "My Drive" to the required folder. I can do this with a script but I can't work out why it is doing this in the first place.
I am the owner of all the files and folders.
Any ideas why?
thanks
Also in my environment, I confirmed the same situation with you. Only Google Apps Scripts cannot be copied to the backup folder. I think that this may be a bug. So I thought of the workaround for this situation. The patterns I tested are as follows.
addFile()
and removeFile()
.
Drive.Files.copy
of Advanced Google Services.
makeCopy()
.
Drive.Files.update
of Advanced Google Services.
In this modified script, Google Apps Script files are moved from "My Drive" to backup folder using Drive.Files.update
.
var sourceFolderId = "xxxxxx";
var sourceFolder = DriveApp.getFolderById(sourceFolderId);
var latestFiles = sourceFolder.getFiles();
var backupFolderId = "yyyyyy";
var backupFolder = DriveApp.getFolderById(backupFolderId);
while(latestFiles.hasNext()) {
var file = latestFiles.next();
var res = file.makeCopy(backupFolder); // Modified
if (file.getMimeType() == MimeType.GOOGLE_APPS_SCRIPT) { // Added
Drive.Files.update({"parents": [{"id": backupFolderId}]}, res.getId()); // Added
}
}
In order to use this modified script, please enable Drive API at Advanced Google Services and API console as follows.
If I misunderstand your question, I'm sorry.