Home > Enterprise >  Batch file to run a command by pulling input files from another text file and output a separate file
Batch file to run a command by pulling input files from another text file and output a separate file

Time:02-24

I have to download files from a lfs system using mcumgr, but I have a lot of files to download so I was trying to use a batch file.

This is the gist of the command to download:

mcumgr ....fs download /lfs/log/%%x %%x

%%x is the file name.

This is the batch file I was trying:

@echo OFF
setlocal EnableDelayedExpansion
for /f "tokens=* delims==" %%x in (files.txt) DO (
    cmd /k "mcumgr ...fs download /lfs/log/%%x %%x"
)

I created a files.txt, where I paste the list of files to download; but it appends all the outputs into a single text file and I want to have separate output files every time it goes through the loop, (similar to continually running the commands).

Edit: the list of files are similar to this:

86483ef-648274286.txt
7963476-647649836.txt

Any suggestions to go about this?

CodePudding user response:

Your code was close. When the mcumgr command appears correct, remove the ECHO from the beginning of the line.

FOR /F "delims=" %%A IN (files.txt) DO (
    ECHO mcumgr ...fs download "/lfs/log/%%~A" "%%~A"
)

If mcumgr is a .bat or .cmd script, then CALL should be used.

ECHO CALL mcumgr ...fs download "/lfs/log/%%~A" "%%~A"

  • Related