windows bat文件按名称查找文件夹并返回其路径

时间:2016-02-25 20:17:26

标签: windows batch-file

在Windows cmd中,如何按名称搜索文件。然后添加变量以选择其完整路径。 即找到Folder Test1并返回Drive \ somewhere \ test1

def "Test Case"(){
    when:
        butList = ["button1", "button3", "button4",...] //this list is generated somewhere else. it's not actually hard coded like you see here. the buttons in the list depend on the environment
        def pageInstance = new Page1()
        pageInstance.buttonList = butList
    then:
        Thread.sleep(30)
    when:
        //click something to bring me to the Page1 page
    then:
        at pageInstance
    when:
        button3.click()//in this case button 3 exists but this is where the code fails 
    then:
        thread.sleep(5000)
}

1 个答案:

答案 0 :(得分:0)

试试这个:

for /f "usebackq" %a in (`dir /b /s /a-d ^| findstr "Test1"`) do set fileLocation=%~pa
echo %fileLocation%

这里的一个潜在缺点是,如果它在多个文件夹中找到Test1%fileLocation%将只设置它找到的最后一个文件夹。