下面是我为在特定文件中查找“错误”字符串并将结果复制到单独文件而编写的代码。
set today=%date:~-4,4%-%date:~-10,2%-%date:~-7,2%
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "yesterday=%yyyy%-%mm%-%dd%"
findstr /C:"error" "\\abcd023\peak$\Monitor_5.7\logs\monitor-%today%-0.log" >> C:\a\xyz.txt
findstr /C:"error" "\\abcd023\peak$\Monitor_5.7\logs\k-server-%yesterday%-0.log.zip\k-server-%yesterday%-0.log" >> C:\a\xyz.txt
k-server-%昨天%-0.log.zip \: - 因为这是zip文件,它给我错误,因为找不到路径。对于没有zip文件夹的类似路径,它给我结果。
我想扫描zip文件夹中存在的文件而不解压缩该文件夹。
答案 0 :(得分:0)
看看这个:How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools? 您无法在不解压缩文件内容的情况下搜索文件内容,但您只需解压缩一个文件即可。假设您在同一目录中有zipjs.bat:
call zipjs.bat unZipItem -source "\\abcd023\peak$\Monitor_5.7\logs\k-server-%yesterday%-0.log.zip\k-server-%yesterday%-0.log" -destination ".\" -keep yes -force yes
findstr /C:"error" ".\k-server-%yesterday%-0.log" >> C:\a\xyz.txt
del /q /f ".\k-server-%yesterday%-0.log"