批处理全盘搜索指定文件获取其完整路径
【方案一】for /f + dir
@echo off rem 指定待搜索的文件 set "FileName=BatHome_Batcher.txt" echo 正在搜索,请稍候... for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( if exist %%a:\nul ( for /f "delims=" %%b in ('dir /a-d /s /b "%%a:\*%FileName%" 2^>nul') do ( if /i "%%~nxb" equ "%FileName%" ( echo.%%b ) ) ) ) pause
【方案二】for /r(比 for /f + dir 效率高,但不会遍历隐藏文件)
@echo off rem 指定待搜索的文件 set "FileName=BatHome_Batcher.txt" echo 正在搜索,请稍候... for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( if exist %%a:\nul ( pushd %%a:\ for /r %%b in ("*%FileName%") do ( if /i "%%~nxb" equ "%FileName%" ( echo.%%b ) ) popd ) ) pause
【方案三】WMIC(Win2000/WinXP HOME版、WinXP 精简版可能不支持)
@echo off rem 指定待搜索的文件 set "FileName=test 1.bat" echo 正在搜索,请稍候... for %%a in ("%FileName%") do ( set "nName=%%~na" set "xName=%%~xa" ) set "xName=%xName:~1%" for /f "skip=1 delims=" %%a in ('wmic datafile where "filename='%nName%' and Extension='%xName%'" get name') do ( echo.%%a ) pause
【声明】本文 批处理全盘搜索指定文件获取其完整路径 为柠之漠然原创文章,转载请注明出自
枫之落叶
并保留本文有效链接:https://blog.shiniv.com/2013/05/%e6%89%b9%e5%a4%84%e7%90%86%e5%85%a8%e7%9b%98%e6%90%9c%e7%b4%a2%e6%8c%87%e5%ae%9a%e6%96%87%e4%bb%b6%e8%8e%b7%e5%8f%96%e5%85%b6%e5%ae%8c%e6%95%b4%e8%b7%af%e5%be%84/ , 转载请保留本声明!