【问题标题】:Batch: Open Windows Explorer and enter a search query批处理:打开 Windows 资源管理器并输入搜索查询
【发布时间】:2017-05-10 15:38:40
【问题描述】:

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

更多信息/最终目标:

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

356 - 22 圣刘易斯大道

357 - 104 Madeitup 广场

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

356-1.pdf

356-2.pdf

356-3.pdf

357-1.pdf

357-2.pdf

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 哇!您的解决方案让我重新评估批处理可用性。做得很好!
    • 非常优雅!感谢您提供如此完整的解决方案。
    【解决方案2】:

    批处理不起作用

    批处理脚本不适合使用 GUI 操作。对于所选工具,描述的目标似乎几乎不可能。也许,批处理可以解决一些重新制定的任务,例如将项目相关发票的软链接制作到 tmp 文件夹中,这样您就可以在一个地方看到它们。尽管如此,恕我直言,解决方案将非常庞大且痛苦。不过,有一个好消息:

    AutoIt 会做

    AutoIt 是一种免费软件,类似 BASIC 的脚本语言,专为 自动化 Windows GUI 和一般脚本。

    准确描述行为的整个脚本总共用了 10 行(不包括 cmets):

    ;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 的机器上正常运行。

    【讨论】:

    • 感谢您的意见,我认为您同意,treintje 的解决方案非常出色。尽管出于兴趣,我会检查 AutoLT,这对我来说是新的!谢谢。
    【解决方案3】:
        SET HPATH="I:\Share\HOTLINE"
        SET /p DriverNb=Enter Driver Number: 
        start "" "search-ms:query=%DriverNb%&crumb=location:%HPATH%&"
    

    【讨论】:

      猜你喜欢
      • 2012-07-21
      • 2016-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-25
      相关资源
      最近更新 更多