Drive api: https://developers.google.com/drive/v2/reference/files/list
I'm trying to get the id of the spreadsheet I have, but the Logger.log() returns multiple id's instead of just the one. I think it's getting the files with the same name from the recent section in google drive.
I don't know how to fix that and any help would be appreciated.
Is there a way to only search files inside of a folder using the drive api? Or how would I exclude the files in the recent section and only search files in my drive?
snippet of code:
//get spreadsheet
var nameId;
var allFiles = Drive.Files.list({
q: "title='" + name + "' and trashed=false"
}).items;
for (var i = 0; i < allFiles.length; i++)
{
if (allFiles[i].title == name)
{
Logger.log("true");
nameId = allFiles[i].id;
Logger.log("returnTemplatedTable -- name id: " + nameId);
}
else
{
Logger.log("false");
}
}
var spreadsheet = SpreadsheetApp.openById(nameId).getActiveSheet();
This is the snippet of code I have that moves a file to a folder:
//move spreadsheet to folder
Drive.Files.update({
"parents": [
{
"id": folderId
}
]
}, fileId);
But how could I search a folder instead?
var list = Drive.Files.list({
"folderId": folderId,
q: "title='" + name + "' and trashed=false"
}).items;
for (var i = 0; i < list.length; i++)
{
Logger.log("id: " + list[i].id);
}