- You want to create new Spreadsheet in the specific folder using Google Apps Script.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Issue and workaround
Unfortunately, the method of "createFile" cannot create the Google Docs. I think that this is the specification of Google side. So it is required to use the workaround. Here, I would like to propose the following 2 patterns.
Pattern 1
In this pattern, Drive Service is used. In this case, the Spreadsheet is created to the root folder and the Spreadsheet is moved to the specific folder.
var Rsheet;
if (folders.hasNext()) {
var folder = folders.next();
Rsheet = SpreadsheetApp.create(folderlisting);
var file = DriveApp.getFileById(Rsheet.getId());
DriveApp.getRootFolder().removeFile(file);
folder.addFile(file);
}
Pattern 2
var Rsheet, fileId;
if (folders.hasNext()) {
var folder = folders.next();
var file = Drive.Files.insert({title: folderlisting, mimeType: MimeType.GOOGLE_SHEETS, parents: [{id: folder.getId()}]});
fileId = file.id;
}
if (fileId) Rsheet = SpreadsheetApp.openById(fileId);
References
If this was not the direction you expect, I apologize.