批处理:打开Windows资源管理器并输入搜索查询

时间:2017-05-10 15:38:40

标签: batch-file windows-explorer windows-search

根据标题,我可以使用批处理打开特定文件夹(始终相同)并输入搜索查询(在窗口右上方搜索框的框中)?

更多信息/最终目标:

我们有一个'Projects'文件夹,其中包含每个项目的子文件夹列表。每个子文件夹名称都以作业编号开头,即:

  

356 - 22 St. Lewes Avenue

     

357 - 104 Madeitup Square

项目的发票文件(pdf)全部分别存储在一个“发票”文件夹中。每个项目可能有多个发票,因此文件夹中的文件如下所示:

  

356-1.pdf

     

356-2.pdf

     

356-3.pdf

     

357-1.pdf

     

357-2.pdf

我的最终游戏是能够在每个项目文件夹中打开一个通用批处理文件,该文件夹将打开Invoice文件夹,并通过从项目文件夹名称解析项目编号,将其输入搜索框并仅显示相关的发票那个项目。

3 个答案:

答案 0 :(得分:2)

第一行采用批处理文件所在目录的名称,并将其存储在名为 pd 的变量中。第二行启动搜索查询,该查询在名为" ... \ invoice&#34的目录中搜索名称包含 pd 变量的前3个字符的任何文件或文件夹; (将其替换为实际 Invoice 目录的完整路径。)

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

答案 1 :(得分:0)

批次无法正常工作

批处理脚本不适用于GUI。对于所选工具来说,所描述的目标似乎很难实现。或许,批次可以解决一些重新制定的任务,例如将项目相关发票的软链接设置到tmp文件夹中,这样您就可以在一个地方看到它们。不过,恕我直言,解决方案将是相当大和痛苦的。然而,有一个好消息:

AutoIt将执行

  

AutoIt是一种免费的类似BASIC的脚本语言   自动化Windows GUI和常规脚本。

完全描述行为的整个脚本总共需要10行(不包括注释):

;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)

为了跑步:

  • 安装AutoIt
  • 在项目文件夹中创建 script_name.au3 文本文件并粘贴提供的代码
  • 双击

您可以将脚本打包成可执行文件,如果需要,可以在没有AutoIt的计算机上正常运行。

答案 2 :(得分:0)

    SET HPATH="I:\Share\HOTLINE"
    SET /p DriverNb=Enter Driver Number: 
    start "" "search-ms:query=%DriverNb%&crumb=location:%HPATH%&"