파일에 두 번째 줄 (:: echo1, :: echo2 및 :: echo3)의 문자열이 있는지 확인하기 위해 다음 코드를 사용합니다. 그러나, 내가 서브 루틴에서 어떤 이유로 내 코드를 실행하면 : _verify IF 명령 내에서 IF 명령 내에서 변수 % chk %를 증가시키는 IF의 else 섹션을 완전히 건너 뛰고 _verify로 돌아 오면 차례대로 숫자가 증가합니다 of : :: 그것은 파일에서 찾고 있으며 같은 파일을 다시 검색합니다 (모든 파일에 대해 각 파일을 검색해야 함). IF 명령을 IF NOT으로 바꾸고 다른 것을 앞뒤로 바꾸어 보았습니다. _redeem하지만 마지막으로 같은 오류가 발생했습니다. (참고 : 그것은 완료 전화를했습니다 : _verify 올바르게 포함 된 파일에 대한 : : echo1). % kk %를 증가시키지 않으므로 :: echo1에 대해서만 각 파일을 검사하고 _verify로 다시 이동합니다. 대신 직접 goto : eof로 이동하여 다음으로 돌아갑니다. 다시 다른 파일을 찾으려면 식별하고 :: echo1 만 처리하십시오. 스크립트를 설명하는 데 도움이되는 설명을 추가했습니다.문자열 용 파일을 처리하는 Windows 배치
set gt1=1
setLocal EnableDelayedExpansion
::Identifies all files meeting the criteria (name being tmp*.tmp) and sets cap%gt1% equal the filename. Also checks to see if there are no files left (if the filename doesn't exist (i.e. it's blank because there are none left)).
:identify
set chk=1
if %gt1%==4 goto :restore
for %%A in (tmp*.tmp) do (set cap%gt1%=%%A) & call :_verify
if not exist !cap%gt1%! goto :error
goto :identify
:_verify
::Verifies that the specific file it's looking at (set as cap%gt1% in :identify) has the string ::echo1, 2 or 3 as the second line.
if %chk%==4 call :_reserve & goto :eof
for /f "skip=1" %%B in (!cap%gt1%!) do if %%B==::echo%chk% (call :_redeem) else (set /a chk=%chk%+1) & (goto :_verify)
goto :eof
:_redeem
::Renames files that are confirmed to have the string to their string name (minus the ::).
ren !cap%gt1%! echo%chk%.tmp
set /a gt1=%gt1%+1
goto :eof
:_reserve
::Subroutine used to temporairly discard files that do not meet the requirements so they will not be processed again in :identify during loopback.
if not exist temp50 mkdir temp50
move !cap%gt1%! temp50
goto :eof
:restore
::Restores files that were put in :_reserve to their previous location.
if exist %~dp0\temp50 cd temp50 & for %%C in (tmp*.tmp) do move %%C %~dp0 & cd .. & rmdir temp50
pause
:error
::Error in case it can't find all three files containing the strings.
echo Unable to find program files. Please reinstall.
echo.
pause
quit
하하하, 감사합니다, Jeb. 나는 당신이 응답 할 4AM 때까지 그냥 기다렸다가 알았어. :피 –