Reputation: 119
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.
Upvotes: 0
Views: 3561
Reputation: 1
SET HPATH="I:\Share\HOTLINE"
SET /p DriverNb=Enter Driver Number:
start "" "search-ms:query=%DriverNb%&crumb=location:%HPATH%&"
Upvotes: 0
Reputation: 3183
Batch scripts aren't meant to operate with GUI. Described goal seems hard to impossible for chosen tool. Perhaps, batch can solve some re-formulated task, e.g. make soft links for project related invoices into tmp folder, so you can see them in one place. Still, IMHO, solution will be quite large and painful. However, there is a good news:
AutoIt is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.
Whole script for exactly described behaviour took total of 10 lines (not counting comments):
;script is supposed to be run from root folder of any individual project
#include <File.au3>
;split full project path into array of folder names
Global $aProjFolderTree = StringSplit(@WorkingDir, "\/")
;get name of the last folder. It should be project name like "356 - 22 St. Lewes Avenue"
Global $sProjLastFolderName = $aProjFolderTree[$aProjFolderTree[0]]
;split project name into words
Global $aProjNameWords = StringSplit($sProjLastFolderName, " ")
;get the first word which is project ID like "356"
Global $sProjId = $aProjNameWords[1]
;open invoice directory in explorer
Global $sInvoiceFolder = _PathFull("..\invoice", @WorkingDir)
Run('explorer.exe ' & $sInvoiceFolder)
;wait until it's ready
WinWaitActive("invoice", "", 10)
;click onto "search" control. NB! control ID may differ on your system, use "AutoIt Window Info" tool to check
ControlClick( "[LAST]", "", "[CLASS:DirectUIHWND; INSTANCE:1]")
;put project Id into it
ControlSend( "[LAST]", "", "[CLASS:DirectUIHWND; INSTANCE:1]", $sProjId)
In order to run:
You can pack script into executable, which will run fine on machines without AutoIt, if needed.
Upvotes: 0
Reputation: 4732
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&"
Upvotes: 2