私はclient.propsという名前の既存のファイルを持っていますので、ドキュメントを読み込んでroot=
を見つけてroot=path_of_file
に置き換えるバッチスクリプトを作成する必要があります。私は以下のスクリプトを使用しました:バッチスクリプトを使用してファイル内のテキストを見つけて置き換える方法
@echo off
setlocal enableextensions disabledelayedexpansion
set "search=root="
set "replace=root=%~dp0"
set "textFile=client.props"
set "textFile1=client1.props"
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile1%" ') do
(
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
>>"%textFile1%" echo(!line!
endlocal
)
私はバッチスクリプトでそれほど役に立ちません。親切に私を助けてください。ファイルがF:\temp\file\client.props
で利用可能で、行の1つがroot=
で始まっている場合、バッチはroot=F:\temp\file
と変更する必要があります。ため=
符号は、サブ文字列置換構文!line:%search%=%replace%!
内で使用することができない
root=F:\temp\file
'do'の後に 'do'は 'do 'と同じ行になければなりません! – aschipfl