@echo off
setlocal DisableDelayedExpansion
rem Load the replacement table from conf.txt file
set n=0
for /F "usebackq delims=" %%a in ("%~P0conf.txt") do (
set "line=%%a"
set /A n+=1
setlocal EnableDelayedExpansion
rem Use the first special character here, after second equal-sign and 15 characters forward
rem and the second special character after the third equal-sign
for /F "tokens=1,2 delims=Ç" %%b in ("!n!Ç!line::::=ü!") do (
endlocal
set "replace[%%b]=%%c"
)
)
rem Process all HTML files in toChange folder
setlocal DisableDelayedExpansion
cd "C:\toChange"
for /R %%a in (*.html) do (
rem Process all lines of this file
(for /F "usebackq delims=" %%b in ("%%a") do (
set "line=%%b"
setlocal EnableDelayedExpansion
rem Make the replacements
for /L %%i in (1,1,%n%) do (
rem Use the second special character here, after second equal-sign
for /F "tokens=1,2 delims=ü" %%c in ("!replace[%%i]!") do (
set "line=!line:%%d=%%c!"
)
)
echo !line!
endlocal
)) > "%%a.txt"
rem Remove the REM in next lines to delete original .html file and rename the created one
REM del "%%a"
REM ren "%%a.txt" "%%~NXa"
)
上記のバッチ プログラムは、元のファイルと同じ名前に ".txt" 拡張子が追加されたファイルで出力を生成します。結果が正しい場合は、バッチ ファイルの末尾にある REM コマンドを削除して、元の .hmtl ファイルを削除し、作成したファイルの名前を変更します。このデータを使用してプログラムをテストしました。
conf.txt
AAA.PY_ERROR_OCCURRED_WHILE_GETTING_PAYMENT_LIST_SCREEN_FOR_ORG_TYPE:::"Error occurred while getting payment list screen for org type: "
AAA.PY_AO_PAYMENT_LIST_SIZE:::"aoPaymentListSize"
AAA.PY_AO_PAYMENT_STATUS:::"aoPaymentStatus"
aaa.FIRE_FOX:::"firefox"
aaa.MSIE:::"msie"
aaa.IE_7:::"msie 7"
example.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- Example HTML file -->
Normal text. <b>Bold text.</b> <i>Italic text.</i>
if (loUserAgent.toLowerCase().indexOf("firefox") > -1
|| (loUserAgent.toLowerCase().indexOf("msie") > -1 && loUserAgent.toLowerCase().indexOf("msie 7") != -1))
出力: example.html.txt
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- Example HTML file -->
Normal text. <b>Bold text.</b> <i>Italic text.</i>
if (loUserAgent.toLowerCase().indexOf(aaa.FIRE_FOX) > -1
|| (loUserAgent.toLowerCase().indexOf(aaa.MSIE) > -1 && loUserAgent.toLowerCase().indexOf(aaa.IE_7) != -1))
conf.txt ファイルは、バッチ ファイルと同じフォルダーにある必要があります。
プログラムは入力ファイルから空行を削除します。これは、必要に応じて簡単に修正できます。
プログラムは多少遅くなる場合があります。これはある程度改善される可能性がありますが、大幅な変更が必要です。
編集:次の目的で、このプログラムの以前のバージョンを変更しました。
- conf.txt ファイルの感嘆符を正しく処理します。
- 等号の代わりに特殊文字を使用して、conf.txt ファイルの置換値を区切ります。
のように、文字の組み合わせを独自のテキストのセパレータとして使用できることに注意してください。ただし:::
、特定のバッチ管理では、セパレータは1文字である必要があります。この詳細により、conf.txt ファイル内に表示されてはならない特定の文字を選択する必要があります。私のプログラムでは、区切り文字として2 つの異なる特殊文字を使用する必要があります。アスキー文字 128 (Ç) と 129 (ü) を選択しました。これらの文字が conf.txt ファイルに表示される可能性がある場合は、別の文字を選択し、プログラム内の指定されたポイントで変更する必要があります。申し訳ありませんが、バッチ ファイルでこれを行う方法は他にありません。