jdavis
jdavis

Reputation: 8655

Searching Google Drive within a specific folder

I am trying to utilize Google Drive as repository for many different types of documents. I have those documents arranged in several different folders.

When I perform a search it seems to search my entire Google Drive account for matching results regardless of the fact that I am currently within a specific folder.

This poses a problem for me as I want to be able to refine my searches to within a given grouping of documents.

If I am searching for documents related to my work, for instance, I don't want documents showing up in my search that are personal, or in my personal directories.

Is there a way to refine my search to only show documents within a specified folder and it's subfolders? I know I can refine the search based on file type and ownership, but that doesn't work for me.

Thanks in advance.

Upvotes: 14

Views: 8593

Answers (6)

GS Shahid
GS Shahid

Reputation: 39

There is another workaround that do NOT require any third party app or extension.

  • Remove your folder (In which you wanna search something)
  • Search with is:trashed filter. For example: is:trashed query_string
  • Restore your folder back

Upvotes: 0

kissrobber
kissrobber

Reputation: 577

I implemented the function in this Chrome Extension. https://chrome.google.com/webstore/detail/advanced-drive-search/chomjcpadndbjgkanbaakmjehdoighab

You can check the code here https://github.com/kissrobber/advanced_google_drive_search_chrome_extension

What that do is

  • get all the folders
  • build a query with the folder_id and the descendant folder_ids. Like this (<folder_id> in parents or <folder_id> in parents or ....)

If you have concern with the performance, try the Chrome extension.

Upvotes: 0

Travis H
Travis H

Reputation: 11

The code I have included allows me to search the body of files within a specific folder. I am using it to search scanned documents and will have it move the file to another folder based on search criteria I specify.

The great thing about this is that it will search the body of the document and return all documents that meet your search criteria. As you can see I can also specify a date range and you can use other operators to define your search. https://developers.google.com/drive/web/search-parameters.

This was a great find for me and I hope it can help some others.

function searchFolder(){
var parent = DriveApp.getFolderById(‘*******************’); // folder Id
var search = 'modifiedDate >"2014-08-01" and modifiedDate  < "2014-12-31" and fullText contains "PUT   SEARCH TEXT HERE"';
var specificFolder = parent.searchFiles(search);

while (specificFolder.hasNext()) {
  var file = specificFolder.next();
  Logger.log(file.getName());
  Logger.log(file.getId());
  }

 }

Upvotes: 1

jpp
jpp

Reputation: 349

I found a sort of workaround using the description field.

In my particular case, all the files created in the folder i want to search are created programmatically by my own script, but is quite simple to write a script to (re)define the description field into all the files in a specific folder using .setDescription(DESCRIPTION). Once this is done...

The good news is that the standard search in google drive give results based on the description field, including the value set on it into the search field (plus any data you want to find into those files) you will get the results you need.

Of course you need to scarify the description field (or, at least, overcrowd it;-)

As, I think all of you, I'm still waiting for the folder keyword in the standard serch field.

Upvotes: 0

user165768
user165768

Reputation: 1

As far as I know you'd have to do this for each subfolder, but the API (and my app) will search by folder.

I wrote an app that uses the API to search by folder. It is a bit slow so be patient when it is loading.

https://script.google.com/macros/s/AKfycby6G32K-vKCiLmoKvMtG64cYPHEREEx1PY5IoYrEYaR6WAfbXs/exec

// -----------------
var sr = DocsList.getFolder("temp_scripts").find("var");
var i = 0;
for(i=0;i<sr.length;i++)
{
  var r = sr[i];
  Logger.log('name='+r.getName());
  Logger.log('parent=' +r.getParents()[0].getName() );
  Logger.log('---');
}
// -----------------

Upvotes: 0

Ali Afshar
Ali Afshar

Reputation: 41633

Using the Google Drive SDK, you can perform a search query for <folder_id> in parents.

Upvotes: 5

Related Questions