findFile

来源:互联网 发布:js 遍历dom元素集合 编辑:程序博客网 时间:2024/06/10 17:22
findFile查找包含字符串的文件,并列出该字符串在该文件所在的列。
第一参数要查找的字符串。
第二参数查找字符串的文件。支持正规表达是。
注1系统的find命令并不会在子目录中查找,而findFile会在子目录中查找
注2:findFile只会列出包含字符串的文件,而系统的find命令还会列出没有包含字符串的文件。比如:---------- 1.TXT。
使用实例
实例1
findFile "hubin" *.txt
源码文件findFile.bat如下
set fileName=%2
set temp=%0~temp.txt
set string=%string:"=%
if not defined string (
goto popvar
)
if not defined fileName (
set fileName=*
)
if exist %temp% (
del %temp% /q
)
FOR /F "delims=" %%i IN ('dir %fileName% /s/b/a:-d') DO (
find /n "%string%" "%%i">>%temp%
)
FOR /F "usebackq tokens=1,* delims= " %%i IN (%temp%) DO (
if "%%i" NEQ "----------" (
if defined fileName (
echo !fileName!
set fileName=
)
echo %%i
) else (
set fileName=%%j
)
)
if exist %temp% (
del %temp% /q
)
:popvar
set string=!%0~string!
set fileName=!%0~fileName!
set temp=!%0~temp!
:end
原创粉丝点击