title: Replacing text in a filename in Google scripts
body: <p>I want to copy a file and rename it at the same time.  My script searches through the directory for all the relevant files, copies and then renames them.  I can copy them into a different directory or with appending something to the name, but I cannot find how to replace part of the text in the name with other text.</p>
  
  <p>I have tried replace and replaceText, neither seem to change the filename but rather look at the contents of the file.  In the code below I want to save the filename into FileRenameStart and then replace Oldmonth with NewMonth but I just cannot find the right way to do it it.  Anyone able to help?</p>
  
  <p>Thanks</p>
  
  <pre><code>    function newMonthFunction() {
  
    // what files we want
   var OldMonth = "July 2016";
   var NewMonth = "August 2016";
   var FindThisText = "Core " + OldMonth;
   files = DriveApp.searchFiles('title contains "' + FindThisText + '"  and mimeType = "application/vnd.google-apps.spreadsheet"');
   var files = DriveApp.searchFiles('title contains "' + FindThisText + '" and mimeType = "application/vnd.google-apps.spreadsheet"');
  
    while (files.hasNext()) {
      var file = files.next();
      Logger.log(file);
      var file = DriveApp.getFileById(file.getId());
      var FileRenameStart =file.getName();
      var FileRenameend =FileRenameStart
      DriveApp.getFileById(file.getId()).makeCopy(FileRenameEnd)
  
      }
  }
  </code></pre>