1
votes

I have a folder in Google Drive id=0B9TZEwAceBn6flc5Z3RncmFZZkgtQy1sZUNKMHdkMHdiMEkxOVVkT3hYajBZNEYwbzlRUVk. this folder have 163 files(162 XLS + 1 JSON ). I am trying to access this folder with Advanced Google Services Drive (https://developers.google.com/apps-script/advanced/drive) and get count 263.

My app Script Code

var count=0;
var itemsIndex=0;
var quotaLength=0;
var items=[]
function convertExcelToGoogleSpreedSheet() {
   var folderId = '0B9TZEwAceBn6flc5Z3RncmFZZkgtQy1sZUNKMHdkMHdiMEkxOVVkT3hYajBZNEYwbzlRUVk'
   Logger.log(folderId)         
   var pageToken
  do{
    Logger.log("Inside while Loop")
    files = Drive.Children.list(folderId,{pageToken:pageToken}); //have limit of 100 files in one time.    
    pageToken = files.nextPageToken;
    Logger.log('item length'+files.items.length)
    items=items.concat(files.items)  
  }while(files.nextPageToken) 
  Logger.log(items.length)
//   convertFile(itemsIndex,items);   
   Logger.log("Count="+count)
}

Log output

[15-02-20 08:04:22:287 IST] Inside while Loop
[15-02-20 08:04:22:645 IST] item length100
[15-02-20 08:04:22:645 IST] Inside while Loop
[15-02-20 08:04:22:964 IST] item length100
[15-02-20 08:04:22:965 IST] Inside while Loop
[15-02-20 08:04:23:287 IST] item length63
[15-02-20 08:04:23:287 IST] Total Count=263

I am trying to convert these XLS file to Google Spreed sheet for creating data for my website http://bnifsc.in

1
Are you getting trashed files within your results? See developers.google.com/drive/web/search-parameterspinoyyid
Yes this code returned some trashed files. so I am created a new folder and moved all 163 files to new folder and its worked .vinay mavi
you simply need to add "trashed=false" to the q parameter. See the link I sent youpinoyyid

1 Answers

0
votes

You can pass the maxResults parameter and it can return all the files in a single call.

files = Drive.Children.list(folderId, {maxResults: 1000, pageToken:pageToken});