So, I'm trying to copy a file which is updated automatically in my computer in a folder. Thing is that every time the script runs, it copies the file in the selected folder but also creates a duplication in the root folder despite root isn't referred in the whole script
function moveFiles() {
var olderfiles = DriveApp.getFolderById("idfromdestinyfolder").getFiles();
while (olderfiles.hasNext()) {
var olderfile = olderfiles.next();
var pull = DriveApp.getFolderById("idfromdestinyfolder");
pull.removeFile(olderfile)
}
var files = DriveApp.getFolderById("idfromstartingfolder").getFiles();
while (files.hasNext()) {
var file = files.next();
var destination = DriveApp.getFolderById("idfromdestinyfolder");
file.makeCopy("nameofthefile",destination);
}
}
The first part olderfiles checks if a file exist in the destiny, and if exists, it removes it. The second part copies the file from the starting folder to destination.
Thing is, every time it runs, it creates a copy in root which should not happen. Is the first time I'm using google script