batch-filewindows-explorerwindows-search

Batch: Open Windows Explorer and enter a search query


As per title, can I use batch to open a specific folder (always the same) and enter a search query (in the box at the search box top-right of the window)?

More info / End goal:

We have a 'Projects' folder the containing a list of sub-folders for each of our projects. Each sub folder name begins with a job number, i.e:

356 - 22 St. Lewes Avenue

357 - 104 Madeitup Square

Invoice files (pdf's) for projects are all stored separately in a single 'Invoice' folder. There might be multiple invoices for each project, so files in the folder would look like this:

356-1.pdf

356-2.pdf

356-3.pdf

357-1.pdf

357-2.pdf

My end game is to be able to have a generic batch file in each project folder that will open the Invoice folder and, by parsing the project number from the project folder name, enter this into the search box and only show invoices related to that project.


Solution

  • The first line takes the name of the directory where the batch file is located and stores it in a variable called pd. The second line starts a search query that searches for any file or folder whose name contains the first 3 characters of the pd variable in the directory named "...\invoice" (replace this with the full path of the actual Invoice directory).

    for %%* in (.) do set "pd=%%~nx*"
    start "" "search-ms:query=%pd:~0,3%&crumb=location:...\invoice&"