how to use batch file variable within text file?

2020-01-19 04:31发布

问题:

I need to use variable from batch file within a text file. Not sure what's the best and easiest way to achieve that.

Batch file code:

set back=%cd%
for /d %%i in (C:\input\*) do (
cd "%%i"
set x=%%~nxi
CALL E:\FileMoving_run.bat --context=Default --context_param prop_file_move=C:\file_move.txt
cd %back%
pause
)
cd %back%

Content of text file -C:\file_move.txt specified below. The way I am trying to pass here is definitely not working.

path=C:\Metadata_input\%x%\
elec_path=C:\OHD\%x%\

回答1:

Based upon my understanding of your question, you could try:

@For /D %%A In ("C:\input\*")Do @(
    (Echo path=C:\Metadata_input\%%~nxA\
    Echo elec_path=C:\OHD\%%~nxA\)>"C:\file_move.txt"
    Call "E:\FileMoving_run.bat" --context=Default --context_param prop_file_move="C:\file_move.txt"
)
@Del "C:\file_move.txt"