原因找到了,经9527提醒,原来是因为忘记用参数/-c了,它用来去掉分隔符,所以代码改为
@echo off
md h:\5
xcopy/s/e/q i:\*.* h:\5>nul&cd/d h:\5
if exist *.bak del *.bak
for /f "tokens=1-4 delims= " %%i in ('dir/a/s/-c ^|find "文件"') do set a=%%i&set b=%%j&(if not "%%k"=="" set/a size=%%k/1048576)
echo %a%%b% %size%MB>c:\1.txt
for /f "skip=2 delims=" %%i in ('tree /f h:\5') do @echo. %%i>>c:\1.txt
start c:\1.txt
The reason has been found. Reminded by 9527, it turned out that it was because the parameter /-c was forgotten to be used. It is used to remove the delimiter, so the code is changed to
@echo off
md h:\5
xcopy/s/e/q i:\*.* h:\5>nul&cd/d h:\5
if exist *.bak del *.bak
for /f "tokens=1-4 delims= " %%i in ('dir/a/s/-c ^|find "文件"') do set a=%%i&set b=%%j&(if not "%%k"=="" set/a size=%%k/1048576)
echo %a%%b% %size%MB>c:\1.txt
for /f "skip=2 delims=" %%i in ('tree /f h:\5') do @echo. %%i>>c:\1.txt
start c:\1.txt