I am trying to make a batch file that lists all files in in a folder and sub directors and exports to a csv with file size, I curently have this:
@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
But what I need is the File directory and File path as separate records
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With