Reputation: 6449
With the following code:
gapi.client.drive.files.list({
"q": "name='bait7-the-link-building-tool' and 'root' in parents"
})
.then((response) => {
if (response.result && response.result.files && response.result.files[0]) {
console.log("response.result.files[0]", response.result.files[0]);
return response.result.files[0].id;
//
} else {
//create the folder;
}
}, (error) => {
console.error(error);
});
I can check if a folder exist or not in the root of the current user google drive.
And 'root' in parents
does actually work, if the folder is not in the root, I am getting no results.
But... If the folder have been removed/deleted, not permanently, it still return the result, like if the google drive trashcan was the root.
I tried checking the parents adding fields: 'files(kind,id,name,parents)'
to the query, but either the folder is in the root or in the trashcan it always show the same parent id, which lead me to assume it's just the way it is for google drive, a file in the trashcan is indeed a root file for google.
I know if I want to skip the folder/file all together I can just change the query to include and trashed=false
but what if you still want to find the file but know if it's trashed or not?
In the file definition there's a field trashedTime but even if you request it with fields: files(kind,id,name,parents,trashedTime)
it's not returning it.
There must be something I still have not understood of how it works. Anyone knows how to do this?
Upvotes: 1
Views: 1339
Reputation: 4165
You can use the q
URL parameter to filter out files that have been trashed:
https://www.googleapis.com/drive/v3/files?q=mimeType='application/vnd.my-mime-type' and trashed=false
Upvotes: 0
Reputation: 116869
Have you tried adding trashed false to your search parms?
name='bait7-the-link-building-tool' and 'root' in parents and trashed = false'
This will ensure that trashed files are not returned. Doc on search
Upvotes: 0
Reputation: 201368
How about checking trashed
or explicitlyTrashed
for the fields? It's fields=files(trashed,explicitlyTrashed)
. When that is true, it is indicates that the file is in the trashbox.
If I misunderstand your question, I'm sorry.
Upvotes: 2