title: How can I do a copy of my spreadsheet into specifc folder in google drive using Google Script
body: <p>I have the following script that when end of run, I want to make a copy of that spreadsheet into a specific folder with name + date, for example:</p>
  
  <p>I have the spreadsheet called "Audit", When some specific script run at the end I want to make a copy for the spreadsheet into the folder root/Audit/Historic into google driver or google docs.</p>
  
  <p>Note: root is the google driver or google docs top folder.</p>
  
  <p>Script:</p>
  
  <pre><code>  function ShellCopyValues(){
          var sheets = ['sheet1','sheet2','sheet3','sheet4','sheet4'];
          for (var s in sheets){
          CopyRows(sheets[s]);
        }
    }
  
    function CopyRows(uname) {
     var source = SpreadsheetApp.openById('XXXXXX');
     var sourcesheet = source.getSheetByName(uname);
  
     var target = SpreadsheetApp.openById('YYYYYY');
     var targetsheet = target.getSheetByName(uname);
     var targetrange = targetsheet.getRange(2, 1, sourcesheet.getLastRow(), sourcesheet.getLastColumn());
     var rangeValues = sourcesheet.getRange(2, 1, sourcesheet.getLastRow(), sourcesheet.getLastColumn()).getValues();
     targetrange.setValues(rangeValues);
  
     }
  </code></pre>
  
  <p>At the end of this script I want to make a copy.</p>
  
  <p>I will appreciate if anyone have any idea about how can I do it.</p>
  
  <h1>EDIT: 08/07/2013 (Fixed)</h1>
  
  <ul>
  <li>The script will make a copy with this format (filename+date)</li>
  <li><p>The script will save the file into a folder. (Will not appear in the root "My Driver")</p>
  
  <pre><code>//This part make a copy of the spreadsheet
  var SSID = 'XXXXXX'
  var CopyDate = Utilities.formatDate(new Date(), "GMT-3", "ddMMyyyyHHmm"); // Function Date + Format
  var folder = DocsList.getFolder('Historic'); //Use this line if you want to get the folder by name
  //--&gt; var folder = DocsList.getFileById('YYYYY'); //Use this line if you want to get the folder by ID
  var backup = DocsList.getFileById(SSID).makeCopy(SpreadsheetApp.openById(SSID).getName() + "_" + CopyDate);
  backup.addToFolder(folder); //This line will be move the folder
  backup.removeFromFolder(DocsList.getRootFolder()); //This line is needed to remove the Filde from the Root
  </code></pre></li>
  </ul>