I am trying to download a file from a folder in Google Drive to a folder in my local PC using Google Apps Script. However, I couldn't find a proper way to do it. The files are usually .pdf, .csv, or .docx. And I want to save them to a specific folder in my local computer with a trigger, so that the script will work even when my computer is in sleep. Is this even possible?
I am also okay for a solution that works when my PC is open.
For now I am able to reach the files but couldn't find a way to download them to my local.
function downloadFiles() {
var driveApp = DriveApp
var folderIter = driveApp.getFoldersByName('DownloadTrys')
var folder = folderIter.next()
var filesIter = folder.getFiles()
var localFolder = "C:\\Users\\XXXX\\Desktop\\personal\\"
//var file = DriveApp.getFileById("downloadthis.txt");
while(filesIter.hasNext()){
var file = filesIter.next();
var fileName = file.getName();
Logger.log(fileName);
var blob = file.getBlob();
var filePath = localFolder + fileName
Logger.log(filePath)
var data = Utilities.base64Encode(blob.getBytes());
var localfile = Utilities.newBlob(Utilities.base64Encode(data), blob.getContentType(),filePath)
driveApp.createFile(localfile).setName(fileName).setTrashed(true);
};
}```