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

1
  • Please post a snippet of your current output and that same snippet modified to your desired output. Helps us understand what you want. Commented Oct 4, 2013 at 16:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.