My requirement is to create an output file with the following format: Filename,file size,checksum
An example would be abc.tar,1024 Bytes,052107adc8c42d6cf581bf81225ae6de
setlocal enabledelayedexpansion
set OUTFILE="C:\Script\Batch_OUT.txt"
echo %OUTFILE%
echo Extracting Batch records to %OUTFILE% ...
echo pwd = `pwd`
cd C:\Script\TARS\
for %%f in (Batch_*.tar) do (
(echo %%~nxf && echo %%~zf Bytes && certutil -hashfile "%%f" MD5 | find /V ":") >>%OUTFILE%
)
pause 2m
Batch_one.tar
778240 Bytes
052107adc8c42d6cf581bf81225ae6de
Batch_one.tar,778240 Bytes,052107adc8c42d6cf581bf81225ae6de
You can use the same trick as in the post, David Winder already linked in a comment:
...
for %%f in (test.txt) do (
(
<nul set /p ".= %%~nxf,%%~zf Bytes,"
certutil -hashfile "%%f" MD5 | find /V ":"
) >>%OUTFILE%
)
...