title: Overwrite existing file in a specific Google Drive folder
body: <p>I need the <code>var file = dir.createFile(blob).setContent('Stores_Month.pdf');</code> to every time, overwrite the existing <strong>Stores_Month.pdf</strong> file in the specified Google Drive folder.</p>
  
  <pre><code>function runCBUEBUquarterly() {
  
    var file = DriveApp.getFilesByName("Data_Stores_Quarter.csv").next();
    var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
    var sheet = SpreadsheetApp.getActive().getSheetByName('Data_Month');
    sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
  
  
   /* Highlight all sort range and sort by AS - Okanagan */ 
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = SpreadsheetApp.getActive().getSheetByName('Stores_Month');
    var range = sheet.getRange("A5:AS10");
  
   // Sorts by the values in column (AS)
    range.sort({column: 45, ascending: false});
  
  
     /* Highlight all sort range and sort by AS - LM &amp; Whistler */ 
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = SpreadsheetApp.getActive().getSheetByName('Stores_Month');
    var range = sheet.getRange("A13:AS24");
  
   // Sorts by the values in column (AS)
    range.sort({column: 45, ascending: false});
  
  
   /* Save as PDF to Google Drive */ 
    SpreadsheetApp.flush();
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = SpreadsheetApp.getActive().getSheetByName('Stores_Month');
  
    var url = ss.getUrl();
  
    //remove the trailing 'edit' from the url
    url = url.replace(/edit$/,'');
  
    //additional parameters for exporting the sheet as a pdf
    var url_ext = 'export?exportFormat=pdf&amp;format=pdf' + //export as pdf
    //below parameters are optional...
    '&amp;size=letter' + //paper size
    '&amp;portrait=false' + //orientation, false for landscape
    '&amp;fitw=false' + //fit to width, false for actual size
    '&amp;pagenumbers=true' + //fit to width, false for actual size    
    '&amp;sheetnames=false&amp;printtitle=false' + //hide optional headers and footers
    '&amp;gridlines=false' + //hide gridlines
    '&amp;fzr=true' + //do not repeat row headers (frozen rows) on each page
    '&amp;gid=' + sheet.getSheetId(); //the sheet's Id
  
    var token = ScriptApp.getOAuthToken();
  
    var response = UrlFetchApp.fetch(url + url_ext, {
        headers: {
          'Authorization': 'Bearer ' +  token
        }
      });
  
    var blob = response.getBlob().setName(sheet.getName() + '.pdf');
  
    //from here you should be able to use and manipulate the blob to send and email or create a file per usual.
    //In this example, I save the pdf to drive
  
  
  
    var dir = DriveApp.getFoldersByName('CBU &amp; EBU - Quarterly Tracker').next();
    var file = dir.createFile(blob).setContent('Stores_Month.pdf');
  
  } 
  </code></pre>