我正在尝试制作一个批处理文件,其中列出文件夹和副导演中的所有文件,并导出到具有文件大小的 csv,我目前有这个:
@ECHO OFF &SETLOCAL
(FOR /f "delims=|" %%a IN ('dir /s /b /a-d') DO (
FOR /f "tokens=1-9*" %%x IN ('dir /b /a-d /tc "%%~a"^| C:\Windows\System32\findstr "^[0-9]"') DO (
ECHO %%a, %%z
)
))>DIR.csv
TYPE DIR.csv
Run Code Online (Sandbox Code Playgroud)
但我需要的是文件目录和文件路径作为单独的记录
This can be accomplished with a simple one liner directly from the command line - no batch required.
File names can contain comma, so they should be quoted in your CSV. The following will create a csv with file path, file name, file size on each line.
(for /r %F in (*) do @echo "%~dpF","%~nxF",%~zF) >dir.csv
Run Code Online (Sandbox Code Playgroud)
Double up the percents if used within a batch script.
Type HELP FOR or FOR /? from the command line for documentation on the FOR command. At the bottom is a description of all of the modifiers that can be used when expanding a FOR variable value.