在这里插入代码片
@echo off
setlocal enabledelayedexpansion
color 0a
rem 设置搜索目录
set "searchDir=C:\jgyy"
rem 检查目录是否存在
if not exist "%searchDir%" (
echo 错误: 指定的目录 "%searchDir%" 不存在!
goto :eof
)
rem 获取用户输入的搜索文本
set /p searchText=请输入要搜索的文本:
if "%searchText%"=="" (
echo 错误: 搜索文本不能为空!
goto :eof
)
echo 正在搜索 "%searchDir%" 目录下包含 "%searchText%" 的文件...
echo.
rem 初始化计数器
set fileCount=0
set matchCount=0
rem 遍历目录中的所有文件
for /r "%searchDir%" %%f in (*) do (
set "file=%%f"
rem 检查文件是否为二进制文件(简单判断)
findstr /m /a:00 "." "!file!" >nul 2>nul
if errorlevel 1 (
rem 文件包含二进制数据,跳过
continue
)
rem 搜索文件内容
findstr /n /i /c:"%searchText%" "!file!" >nul
if not errorlevel 1 (
set /a fileCount+=1
echo 找到匹配的文件: !file!
echo ----------------------------------------
rem 显示匹配的行
for /f "tokens=1* delims=:" %%a in ('findstr /n /i /c:"%searchText%" "!file!"') do (
set /a matchCount+=1
echo 行号: %%a
echo 内容: %%b
echo.
)
echo.
)
)
echo 搜索完成!
echo 找到 %fileCount% 个包含匹配内容的文件,共 %matchCount% 处匹配。
pause
Window实现fileseek的源码,仅供参考
于 2025-06-17 19:58:22 首次发布