Reputation: 2297
I need to list all files in a drive specific folder. It's working but not really as expected. I get the whole list of files that are in this folder even if the file has been removed and placed in the trash.
How can I only get the files that are really in this folder ?
async listActiveSeries()
{
let _RESULT = null;
try
{
const auth = await this._makeClient();
const googleDriveClient = google.drive({ version: 'v3', auth });
const response = await googleDriveClient.files.list
({
pageSize: 150,
q: `'${ID_OF_THE_FOLDER}' in parents`
});
if(response && response.data && response.data.files)
{
_RESULT = response.data.files;
}
}
catch(ex)
{ console.log(ex); }
return _RESULT;
}
Upvotes: 1
Views: 6491
Reputation: 29
To get the files from a specific folder you need to do this:
val files = googleSerive
.files()
.list()
.setQ("mimeType='application/vnd.google-apps.folder'")
.setQ("parents='14GyOOlAcGT_AroCwoRyXRWdalnAOykss'")
.setSpaces("drive")
.setFields("nextPageToken, files(id, name, mimeType)")
.setPageSize(20)
.execute()
Where 14GyOOlAcGT_AroCwoRyXRWdalnAOykss it the ID of your parent folder. This Id you can take it from either the Browser URL link or running a similar command as above
googleSerive.files().list()
.setQ("mimeType = 'application/vnd.google-apps.folder'")
.setQ("name = 'YOUR_FOLDER_NAME'")
.setFields("nextPageToken, files(id, name)")
.setPageSize(10)
.execute()
Upvotes: 0
Reputation: 201603
I believe your goal as follows.
In this case, how about using trashed=false
to the search query? When your script is modified, it becomes as follows.
q: `'${ID_OF_THE_FOLDER}' in parents`
q: `'${ID_OF_THE_FOLDER}' in parents and trashed=false`
trashed=false
as AND
, the files in the trash box is not retrieved.Upvotes: 5