Windows 批处理文件 - 在单行中格式化 CertUtil 输出和文件名和大小

Windows Batch file - Format CertUtil output and filename and size in single line

我的要求是创建一个具有以下格式的输出文件:Filename,file size,checksum

例如 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

您可以使用与 post 中相同的技巧,David Winder 已在评论中链接:

...
for %%f in (test.txt) do (  
 (
   <nul set /p ".= %%~nxf,%%~zf Bytes," 
   certutil -hashfile "%%f" MD5 | find /V ":"
 ) >>%OUTFILE%  
) 
...