In my script I have template docs in the main drive, but when the copy is created and populated with my excel data, I want it to be saved in a folder in drive. I have the script do that, but it has one copy of the file in the Main Google Drive, and the other in the folder I want it in. If I delete one of the copies, it deletes both.
Is there any way I can have it save automatically in the specified folder without also being in the main drive folder?
Folders in Google drive are not exactly like forders in a computer : having the file in your ‘root’ folder and in another folder doesn’t mean there are 2 files, but rather 1 and only file with 2 labels… that’s why you can’t delete one without deleting the other !
The solution is simply to play with these labels in the script, here is how it works : (I commented each step to make it clear.)
The other possible solution is to create the file directly in the target folder since the folder object supports the
createFilemethod. (Not sure though that you can do it in your specific use case)here is an example, you can see that the file is not in the root folder.