title: Using Google Apps Script to get files in large folder,next page token issue?
body: <p>I have large google drive folders with about 2900 files, i want to split them into many subfolders,each folder has 100 files
  but when i run my script ,there is only one folder created and about 90 files added to that folder it seems that the script stop here (no files added anymore)</p>
  
  <p>i searched and found a thing "pagetoken" ,it says that i have to loop through next pagetoken to bypass the limit file per page,
  How to loop through pagetoken to get all files in folder, or any method to loop through 2900 files ,please ?
   here is my code :</p>
  
  <pre><code>    function SplitFolder(source,target) {
  
    var files = source.getFiles();
    var i = 0; // count of files, to limit 100 files per folder
    var n = 1; // name of folder = folder count
    var folderidz; // id of folder
    var foldercopied; // target folder to copy
    // create first folder
    folderidz = target.createFolder(n).getId(); // create folder name "1"
    foldercopied = DriveApp.getFolderById(folderidz); // get folder id
      while (files.hasNext()) {
      var file = files.next();
      i++;
      if (i == 100) // if &gt; 100 files ,create new folder
      {
        n++; // number of folder
        i = 0; //reset file count of new folder
        folderidz = target.createFolder(n).getId(); // get id of new created folder
        foldercopied = DriveApp.getFolderById(folderidz); //get folder 
      }
      foldercopied.addFile(file); // copy files to that folder
    }
  }
  </code></pre>