日期:2014-05-17  浏览次数:20899 次

怎样用批处理来打开文件名包含指定字符串的文件呢
假如一个文件夹下有N个文件,我要打开其中一个文件名包含某字符串的文件,该如何打开呢?


比如要打开文件名中含有“search_once”的文件。请问如何编写批处理文件呢?



请各位高手不吝赐教!

------解决方案--------------------
setlocal enabledelayedexpansion
set folder=C:\test
if exist file.txt del file.txt /q
for /f %%a in ('dir /b /a-d %folder%') do echo %%a>>file.txt
for /f %%a in ('findstr "search_once" file.txt') do (
set filename=%%a
start %folder%\!filename!
pause>nul
)