We help IT Professionals succeed at work.

batch file reads and lists contents in a logfile

jjcheap1 asked
Medium Priority
Last Modified: 2013-11-09

I need a batch file that can start in c: and go through each directory and list the file names and date and size and skip the Windows directory.  If it can find the create date and the last modify date that would be great!

Watch Question

Paste the script below into a text file with a .cmd extension.  Running it will create a comma-delimited text file listing the information for every file except those under C:\WINDOWS.  It will take a very long time to run as it has to recurse through the entire file structure on the drive.

@echo off
setlocal enabledelayedexpansion
set root=c:\
set exclude=c:\windows
set report=report.csv
echo Path,Size (bytes),Date Created,Date Modified>"%report%"
for /F "tokens=*" %%G in ('dir "%root%" /A:-D /B /S /T:C ^|findstr /B /I /V /C:"%exclude%\\" 2^>NUL') do (
 for /F "tokens=1-3" %%H in ('dir "%%G" /T:C 2^>NUL') do (
  set output=%%H %%I %%J
  if "!output:~2,1!"=="/" set createdate=!output!
 echo "%%G",%%~zG,!createdate!,%%~tG>>"%report%"

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Excellent Job! Works great!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.