0
謝謝,隨着你的提示我已經調整了我的主批處理文件,但變量TARG_FILE沒有改變。 我試圖從FileList_for_Import.txt包含數據替換查找特殊字符字符串 - 批量
file1.txt
file2.txt
`
Cls
DIR /o-d /b D:\Data\All_Inputfiles\*.* > D:\Data\FileList_for_Import.txt
REM Start Loop thru the file names that are available in FileList_for_Import.txt
REM Loop thru file
SETLOCAL EnableDelayedExpansion
@echo off
Set AllInputFile= D:\Data\FileList_for_Import.txt
SET INTEXTFILE=C:\DataLoader\Load.xml
set OUTTEXTFILE=D:\Data\tmp_out.txt
SET BackupPath=D:\Data\BackupLoad.xml
Set TempFile=D:\Data\tmp.txt
SET DbgFile=D:\Data\debuginfo.txt
Rem Remove Debug files
Del !DbgFile!
REM Del D:\Data\debugerr.txt
ECHO " Start ">!DbgFile!
ECHO !AllInputFile!>>!DbgFile!
ECHO " "###########Start of MAIN OF LOOP ############"
REM pause
for /f "tokens=*" %%a in (!AllInputFile!) do (
set "TARG_FILE=%%a"
REM ECHO line=%%a "TARG_FILE "!TARG_FILE!>>!DbgFile!
REM Get the 2nd line from the debugpayload file
REM for /f "tokens=1*delims=:" %%G in ('findstr /n "^" C:\DataLoader\Load.xml') do if %%G equ 2 set "DbgLine=%%H"
REM ECHO " "DbgLine "!DbgLine!>>!DbgFile!
Del !TempFile!
REM Copy !INTEXTFILE! !BackupPath!
findstr /g "InFilePath" !INTEXTFILE!>!TempFile!
REM set /p "DbgLine="< !TempFile!
set /p DbgLine=< !TempFile!
ECHO "DbgLine "!DbgLine!>>!DbgFile!
SET PREVFILE_NM=!DbgLine:~75,-13!
ECHO "PREVFILE_NM "!PREVFILE_NM! "TARG_FILE " !TARG_FILE! "Before Replace FinalreplaceLine "!FinalreplaceLine!>>!DbgFile!
set FinalreplaceLine=!DbgLine!
REM ECHO "Before Replace FinalreplaceLine "!FinalreplaceLine!>>!DbgFile!
set FinalreplaceLine=!FinalreplaceLine:%PREVFILE_NM%=%TARG_FILE%!
ECHO "FinalreplaceLine "!FinalreplaceLine!>>!DbgFile!
)
` 輸出這批是 !TARG_FILE的文件名!隨每次迭代越來越爲
file1.txt
file2.txt
,但與下面的語句替換它在第一次迭代和第二次迭代它的值不會改變犯規更換FILE1.TXT。
set FinalreplaceLine=!FinalreplaceLine:%PREVFILE_NM%=%TARG_FILE%!
在此先感謝您的幫助或寶貴建議。
檢查我的編輯環路問題。 – SachaDee