Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 我如何排除某些东西出现在FindStr中?_Batch File_Findstr - Fatal编程技术网

Batch file 我如何排除某些东西出现在FindStr中?

Batch file 我如何排除某些东西出现在FindStr中?,batch-file,findstr,Batch File,Findstr,我需要找到多个字符串,但我查找的字符串本身有一个标记。我搜索字符串Incognito和包含它标志的批。我如何防止这种情况 编辑:这是我当前代码的一个片段。基本上,它会打开文本文件,并在其中显示该批处理文件和其他内容,这很好,但我不需要它来标记该批处理文件 findstr /i /s /m "Obligatory" *.* > str-unfixed.txt if %errorlevel%==0 ( Call :TypeWriter "Obligatory Strings Found."

我需要找到多个字符串,但我查找的字符串本身有一个标记。我搜索字符串Incognito和包含它标志的批。我如何防止这种情况


编辑:这是我当前代码的一个片段。基本上,它会打开文本文件,并在其中显示该批处理文件和其他内容,这很好,但我不需要它来标记该批处理文件

findstr /i /s /m "Obligatory" *.* > str-unfixed.txt
if %errorlevel%==0 (
Call :TypeWriter "Obligatory Strings Found."
) else (
Call :TypeWriter "No Obligatory Strings Found."
)
start "" "C:\Users\%USERNAME%\Desktop\str-unfixed.txt"
别担心打字机,这只是一个片段


Edit2:感谢Mofi的编辑,但它在控制台上空白,并且没有完成。 完整的脚本。我们开始吧

@echo off
goto Next
::*************************************************************
:TypeWriter
echo(
(
echo strText=wscript.arguments(0^)
echo intTextLen = Len(strText^)
echo intPause = 30
echo For x = 1 to intTextLen
echo     strTempText = Mid(strText,x,1^)
echo     WScript.StdOut.Write strTempText
echo     WScript.Sleep intPause
echo Next
)>%tmp%\%~n0.vbs
@cscript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1"
echo(
exit /b
::**************************************************************
:Next
@echo off
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /i /s /m "Vape" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto VapeNoFileFound
for %%I in ("%OutputFile%") do if %%~zI == 1 goto VapeFileFound
:VapeFileFound
Call :TypeWriter "Vape Strings Found."
goto Kurium
:VapeNoFileFound
Call :TypeWriter "No Vape Strings Found."
goto Kurium

:Kurium
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /i /s /m "Kurium" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto KuriumNoFileFound
for %%I in ("%OutputFile%") do if %%~zI == 1 goto KuriumFileFound
:KuriumFileFound
Call :TypeWriter "Kurium Strings Found."
goto Spook
:KuriumNoFileFound
Call :TypeWriter "No Kurium Strings Found."
goto Spook

:Spook
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /i /s /m "Spook" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto SpookNoFileFound
for %%I in ("%OutputFile%") do if %%~zI == 1 goto SpookFileFound
:SpookFileFound
Call :TypeWriter "Spook Strings Found."
goto Aimassist
:SpookNoFileFound
Call :TypeWriter "No Spook Strings Found."
goto Aimassist

:Aimassist
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /i /s /m "Aimassist" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto AANoFileFound
for %%I in ("%OutputFile%") do if %%~zI == 1 goto AAFileFound
:AAFileFound
Call :TypeWriter "Aim Assist Strings Found."
goto Triggerbot
:AANoFileFound
Call :TypeWriter "No Aim Assist Strings Found."
goto Triggerbot

:Triggerbot
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /i /s /m "Triggerbot" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto TRNoFileFound
for %%I in ("%OutputFile%") do if %%~zI == 1 goto TRFileFound
cscript //nologo "C:\Users\%USERNAME%\Desktop\dedup.vbs" < "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" > "C:\Users\%USERNAME%\Desktop\str-fixed.txt"
del /s /q "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" > nul
:TRFileFound
Call :TypeWriter "Triggerbot Strings Found."
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt"
:TRNoFileFound
Call :TypeWriter "No Triggerbot Strings Found."
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt"

pause > nul
::************************************************

Edit3:谢谢Mofi

我的问题:需要让文本文档中的项目显示在cmd窗口中

脚本:

@echo off
goto Next
::*************************************************************
:TypeWriter
echo(
(
echo strText=wscript.arguments(0^)
echo intTextLen = Len(strText^)
echo intPause = 30
echo For x = 1 to intTextLen
echo     strTempText = Mid(strText,x,1^)
echo     WScript.StdOut.Write strTempText
echo     WScript.Sleep intPause
echo Next
)>%tmp%\%~n0.vbs
@cscript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1"
echo(
exit /b
::**************************************************************
:Next
@echo off
findstr /i /s /m /C:"Vape" /C:"Kurium" /C:"Spook" /C:"Aimassist" /C:"Triggerbot" /C:"Smoothaim" *.* > str-unfixed.txt
cscript //nologo "C:\Users\%USERNAME%\Desktop\dedup.vbs" < "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" > "C:\Users\%USERNAME%\Desktop\str-fixed.txt"
if %errorlevel%==0 (
Call :TypeWriter "Blacklisted Strings Found."
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt"
) else (
Call :TypeWriter "No Blacklisted Strings Found."
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt"
)
pause > nul
::************************************************
@echo关闭
转到下一个
::*************************************************************
:打字机
回音(
(
echo strText=wscript.arguments(0^)
echo intTextLen=Len(strText^)
回声暂停=30
x=1到intTextLen的回声
echo stremptext=Mid(strext,x,1^)
echo WScript.StdOut.Write stremptext
echo WScript.Sleep intPause
下一个回声
)>%tmp%\%~n0.vbs
@cscript.EXE/noLogo“%tmp%\%~n0.vbs”“%~1”
回音(
退出/b
::**************************************************************
:下一个
@回音
findstr/i/s/m/C:“Vape”/C:“Kurium”/C:“Spook”/C:“Aimassist”/C:“Triggerbot”/C:“Smoothaim”***>str-unfixed.txt
cscript//nologo“C:\Users\%USERNAME%\Desktop\dedup.vbs”<“C:\Users\%USERNAME%\Desktop\str unfixed.txt”>“C:\Users\%USERNAME%\Desktop\str fixed.txt”
如果%errorlevel%==0(
调用:打字机“发现黑名单字符串”
启动“”“C:\Users\%USERNAME%\Desktop\str fixed.txt”
)否则(
呼叫:打字机“未找到列入黑名单的字符串。”
启动“”“C:\Users\%USERNAME%\Desktop\str fixed.txt”
)
暂停>nul
::************************************************

批处理文件可以过滤掉,例如使用以下代码:

@echo off
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /I /M /S "Obligatory" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto NoFileFound

call :TypeWriter "Obligatory strings found."
start "" "%OutputFile%"
set "OutputFile="
goto :EOF

:NoFileFound
del "%OutputFile%"
set "OutputFile="
call :TypeWriter "No obligatory string found."
goto :EOF

:TypeWriter
echo %~1
第一个FINDSTR的输出通过第二个FINDSTR进行过滤,第二个FINDSTR输出的所有行不以作为区分大小写的文本字符串搜索的批处理文件的名称结尾

FOR命令用于检查输出文件的文件大小

输出文件是否为空文件,即文件大小等于0字节,除批处理文件本身外,未在任何文件中找到字符串<代码>强制,导致删除输出文件并打印相应消息

否则,在打印找到字符串的消息后,将在与文件扩展名.txt关联的应用程序中打开输出文件

上面的批处理文件在一个子目录而不是整个驱动器C:上进行了两种情况的测试,因为在C:上完成这项测试可能需要相当长的时间:。驱动器C:上有数十万个文件,使用
*.*
作为文件名模式并从驱动器C:的根目录开始搜索字符串时,总共有几十个GiB


编辑1:定义要在两部分中查找的字符串

如上所述,一个更好的解决方案是避免在批处理文件中搜索字符串。这可以通过使用字符串的环境变量通过两个步骤查找和定义环境变量的值来实现

@echo off
setlocal
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"

set "StringToFind=Obli"
set "StringToFind=%StringToFind%gatory"

%SystemRoot%\System32\findstr.exe /I /M /S "%StringToFind%" *.* >"%OutputFile%"

if errorlevel 1 (
    del "%OutputFile%"
    call :TypeWriter "No %StringToFind% strings found."
) else (
    call :TypeWriter "%StringToFind% strings found."
    start "" "%OutputFile%"
)

endlocal
goto :EOF

:TypeWriter
echo %~1
此批处理文件还搜索
强制
,但它不包含此字符串,只包含
Obli
gatory


编辑2:使用省略的转义字符定义要查找的字符串

这是一个解决方案,其中要找到的多个字符串被分配给环境变量,用转义符<代码> ^ <代码>在搜索字符串中间的任何地方来排除批处理文件。

findstr /i /s /m "Obligatory" *.* > str-unfixed.txt
if %errorlevel%==0 (
Call :TypeWriter "Obligatory Strings Found."
) else (
Call :TypeWriter "No Obligatory Strings Found."
)
start "" "C:\Users\%USERNAME%\Desktop\str-unfixed.txt"
将搜索字符串分配给环境变量时,Windows命令解释器会将其删除为在双引号字符串中找不到。请注意,此解决方案要求

set SearchX=S^earch String
不要有1个或多个尾随空格/制表符,因为尾随空格也将分配给环境变量。如果在这些行的末尾有一个不可见的空格或水平制表符作为搜索字符串的一部分,则搜索将不再按预期工作

此外,此批处理代码首先将FINDSTR找到的每个文件名(包含6个搜索字符串之一)输出到控制台窗口,然后将文件名重定向到输出文本文件中

@echo off
setlocal EnableExtensions
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"

rem Define all search strings with omitted escape character.
set Search1=V^ape
set Search2=K^urium
set Search3=S^pook
set Search4=A^imassist
set Search5=T^riggerbot
set Search6=S^moothaim

rem Delete the output file from a previous run if existing at all.
del "%OutputFile%" 2>nul

for /F "delims=" %%I in ('%SystemRoot%\System32\findstr.exe /I /M /S /C:"%Search1%" /C:"%Search2%" /C:"%Search3%" /C:"%Search4%" /C:"%Search5%" /C:"%Search6%" *') do (
    echo %%I
    echo %%I>>"%OutputFile%"
)

if exist "%OutputFile%" (
    call :TypeWriter "Obligatory strings found."
    start "" "%OutputFile%"
) else (
    call :TypeWriter "No obligatory string found."
)
endlocal
goto :EOF

:TypeWriter
echo %~1
要了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读为每个命令显示的所有帮助页面

  • 呼叫/?
  • del/?
  • echo/?
  • endlocal/?
  • findstr/?
  • 获取/?
  • goto/?
  • rem/?
  • 设置/?
  • setlocal/?
  • start/?

另请参阅Microsoft支持文章和Microsoft TechNet文章。

批处理文件可以通过以下代码过滤掉:

@echo off
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt"
%SystemRoot%\System32\findstr.exe /I /M /S "Obligatory" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >"%OutputFile%"
for %%I in ("%OutputFile%") do if %%~zI == 0 goto NoFileFound

call :TypeWriter "Obligatory strings found."
start "" "%OutputFile%"
set "OutputFile="
goto :EOF

:NoFileFound
del "%OutputFile%"
set "OutputFile="
call :TypeWriter "No obligatory string found."
goto :EOF

:TypeWriter
echo %~1
第一个FINDSTR的输出通过第二个FINDSTR进行过滤,第二个FINDSTR输出的所有行不以作为区分大小写的文本字符串搜索的批处理文件的名称结尾

FOR命令用于检查输出文件的文件大小

输出文件是否为空文件,即文件大小等于0字节,除批处理文件本身外,未在任何文件中找到字符串<代码>强制,导致删除输出文件并打印相应消息

否则,在打印找到字符串的消息后,将在与文件扩展名.txt关联的应用程序中打开输出文件

上面的批处理文件在两种情况下都在一个子目录上测试过,而不是在整个驱动器C上测试过:因为在C:上完成可能需要相当长的时间