5

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

UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51
Robbo
  • 87
  • 1
  • 2
  • 6
  • Please post a snippet of your current output and that same snippet modified to your desired output. Helps us understand what you want. – David Ruhmann Oct 04 '13 at 16:02

1 Answers1

6

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.

dbenham
  • 127,446
  • 28
  • 251
  • 390