Board logo

标题: [文件操作] 批处理for /r如何提取指定文件运行? [打印本页]

作者: pdp320921    时间: 2011-4-1 11:33     标题: 批处理for /r如何提取指定文件运行?

我的目的:
搜寻桌面上Test或Test_v3.48文件夹下的setup.exe并运行
(如果搜索结果有多个,只要运行一个
PS:用命令行实现

我的代码:
  1. for /r %userprofile%\desktop %a in (.\Test) do @if exist "%a\setup.exe" cd %a && start %a\setup.exe
复制代码
不知怎么改?
作者: CrLf    时间: 2011-4-1 12:32

既然要筛选文件夹,for /r就不太合适了
  1. @echo off
  2. cd /d "桌面路径"
  3. path Test;Test_v3.48
  4. for %%a in (setup.exe) do start "" "%%~f$path:a"
  5. pause
复制代码

作者: tmplinshi    时间: 2011-4-1 18:33

  1. for /r "%userprofile%\desktop\Test" %a in (setup.exe?) do @start "" "%a" & exit
复制代码

作者: pdp320921    时间: 2011-4-1 20:07

本帖最后由 pdp320921 于 2011-4-1 20:14 编辑

3# tmplinshi
  1. for /r %userprofile%\desktop %a in (.\Test,.\Test_v3.48) do @if exist "%a\setup.exe" cd %a && start %a\setup.exe
复制代码
我试过这个好像~~
作者: tmplinshi    时间: 2011-4-1 21:02

  1. cd /d "%userprofile%\desktop" & for /f "delims=" %a in ('dir /s/b/a:-d "Test\setup.exe" "Test_v3.48\setup.exe"') do @start "" "%a" & exit
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2