1

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);

  };
  
}```
UtkE
  • 21
  • 2
  • Related: https://stackoverflow.com/questions/56215898/ – TheMaster Feb 07 '23 at 11:14
  • I have checked that answer but I couldn't solve my problem with it. I am looking for a more general purpose script that downloads anything in the given drive Folder to a specified local folder. And it needs to work with triggers. – UtkE Feb 07 '23 at 12:33

0 Answers0