박쥐 파일에서 특정 문자열에 대한 텍스트 파일을 검색하려고합니다. 문자열이 있으면 다음 줄에서 그 뒤에 새 문자열을 추가합니다. 아래 코드가 제대로 작동하지 않는 것 같습니다. 어떤 아이디어?
이것은 내 텍스트 파일에서 찾고있는 문자열입니다. [/Script/MyGame.Mode]
텍스트 파일은 다음과 같습니다.
[/Script/Config.Mode]
Something here 1
Something here 2
[/Script/MyGame.Mode]
Something here 1
Something here 2
[/Script/Edit.Mode]
Something here 1
Something here 2
그리고 여기 내가 원하는 모습입니다.
[/Script/Config.Mode]
Something here 1
Something here 2
[/Script/MyGame.Mode]
RedirectReferences=(PackageName="%Package%",PackageURLProtocol="%PackageURLProtocol%",PackageURL="%WebAddress%/%Package%%Ext%",PackageChecksum="")
Something here 1
Something here 2
[/Script/Edit.Mode]
Something here 1
Something here 2
지금까지 제가 가지고있는 코드는 다음과 같습니다.
@echo off
:GETINFO
echo.
echo.
cls
echo.
echo Let's get some information for your config.
echo Note: The information you enter below is case sensitive. You can copy and paste.
echo.
echo Here's a Package Name example: "DM-MyTest-WindowsNoEditor"
echo.
set /p Package=Enter Package Name:
echo.
echo.
echo.
echo The Package URL Protocol will be "http" or "https"
echo.
set /p PackageURLProtocol=Enter Package URL Protocol:
echo.
echo.
echo.
echo Here's a WebAddress example: "www.myredirect.com/test" (Don't add the trailing /)
set /p WebAddress=Enter Redirect(WebAddress)URL:
echo.
echo.
echo.
echo The file extention is usually ".pak"
echo.
set /p Ext=Enter Map File Extention:
echo.
cls
echo.
echo Please wait... Currently Creating Test References.
:SHOWLINE
echo.
set NewURL=RedirectReferences=(PackageName="%Package%",PackageURLProtocol="%PackageURLProtocol%",PackageURL="%WebAddress%/%Package%%Ext%",PackageChecksum=""^^)
pause
:WRITENEW
set inputfile=game.txt
set outputfile=game.temp.txt
(for /f usebackq^ delims^=^ eol^= %%a in ("%inputfile%") do (
if "%%~a"=="[/Script/MyGame.Mode]" call echo %NewURL%
echo %%a
))>>"%outputfile%"
echo.
pause
명령 프롬프트 콘솔에서 게시 된 코드를 실행하면 구문 오류가 표시됩니다.
)는 현재 예상치 못한 문제였습니다.
분명히 내부의 괄호 NewURL
는 루프에서 확장되면 물건을 끊습니다.
간단한 해결책은 call
트릭 을 사용하여 확장을 지연하는 것 입니다.
call echo %%NewURL%%
또는 :
setlocal enableDelayedExpansion & echo !NewURL! & endlocal
또는 다음을 사용하여 닫는 괄호를 이중 이스케이프합니다 ^^
(한 번은 for set
이고 다른 하나 는 루프 내부의 확장 된 값).
set NewURL=.............PackageChecksum=""^^)
또 다른 문제는 출력 파일 이름이 입력 파일 이름과 동일하지만 읽고있는 것과 동일한 파일로 출력을 리디렉션 할 수 없다는 것입니다.
출력 이름을 다른 파일로 변경하십시오. 그런 다음 루프가 완료된 후 원본을 교체하십시오.
set inputfile=game.txt
set outputfile=game.temp.txt
...................
))>>"%outputfile%"
move/y "%outputfile%" "%inputfile%"
그리고 찾은 줄 뒤에 인쇄 할 새 문자열의 순서를 변경하려면 내부 루프 내에서 두 줄을 바꾸면됩니다.
echo %%a
if "%%~a"=="[/Script/MyGame.Mode]" call echo %%NewURL%%
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다