我需要沿着特定目录循环一组文件,并将其文件名,修改日期和文件大小存储到.csv文件中。下面的代码给出了语法错误。请帮助以下:
setlocal enabledelayedexpansion enableextensions
set baseDIR=%1
cd %baseDIR%
FOR /R %%a IN (*) DO
"%%a","%%~ta","%%za" >>test.csv
exit /b %errorlevel%
答案 0 :(得分:0)
可能是
的想法ECHO "%%a","%%~ta","%%za" >>test.csv
没有echo
,批次将尝试执行"%%a","%%~ta","%%za" >>test.csv
答案 1 :(得分:0)
此批处理插入标题并覆盖输出文件:
@Echo off
setlocal
set "baseDIR=%~1"
cd /D "%baseDIR%"
( Echo "filename","dateModified","filesize"
FOR /R %%a IN (*) DO "%%a","%%~ta","%%za"
) >test.csv
答案 2 :(得分:0)
你也可以尝试类似的东西:
@echo off
Set "MasterFolder=%temp%"
Set "OuptFile=Test.csv"
If exist "%OuptFile%" Del "%OuptFile%"
Call :Test "%MasterFolder%" "%OuptFile%"
Start "" "%OuptFile%"
Exit
::**************************************************
:Test <baseDIR> <OuptFile>
set baseDIR=%1
setlocal EnableDelayedExpansion
for /F "delims=" %%a in ('dir /B /A /S %baseDIR%') do (
echo "%%a","%%~ta","%%~za" >> %2
)
exit /b %errorlevel%
::**************************************************