batch file reads and lists contents in a logfile

Posted on 2009-02-12
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!

Question by:jjcheap1
    LVL 38

    Accepted Solution

    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


    Author Comment

    Excellent Job! Works great!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now