废话不多说,直接上代码,额,想用的话,自己保存成bat文件即可。
【方案一】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:\ ( for /f "delims=" %%b in ('dir /a-d /s /b "%%a:\*%FileName%" 2^>nul') do ( if /i "%%~nxb" equ "%FileName%" ( echo,%%b ) ) ) )
【方案二】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:\ ( pushd %%a: for /r %%b in (*%FileName%) do ( if /i "%%~nxb" equ "%FileName%" ( echo,%%b ) ) popd ) )
【方案三】WMIC(Win2000/WinXP HOME版、WinXP 精简版可能不支持)
@echo off rem 指定待搜索的文件 set "FileName=BatHome_Batcher.txt" 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 )
【方案四】使用 Windows7 系统自带的 where 命令
@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:\ ( for /f "delims=" %%b in ('where /r %%a: "%FileName%" 2^>nul') do ( if /i "%%~nxb" equ "%FileName%" ( echo,%%b ) ) ) )