azoundria
azoundria

Reputation: 1025

Get List Of All The File Modified Dates Of All Files In A Folder And All Subfolders

I need to do timesheets for work I did many months ago but I never tracked hours properly. (I did not know there was a need to track this information at the time.)

I figure the most valuable information I could use would be the last modified or date created timestamps on the files during this time period. There should be files created and last modified on most days that I worked, which would help me piece together not only the hours but what I was working on.

What I'm hoping is for some sort of batch script that could recursively go through a directory and all the subdirectories and put the filenames, creation dates, and last modified dates in a text file. I can probably sort in Excel pretty easily once I have the information.

It's a Windows XP computer, but I don't think that the exact version of Windows matters.

Basically, it's How to get the Last Modified date of all files in a folder using Batch but I need to modify that to also have the creation date and be recursive through all the subdirectories (since there are a very large number of directories involved). I have only a very basic level of experience with Batch.

Thanks so much for your help!

Upvotes: 0

Views: 10823

Answers (1)

Magoo
Magoo

Reputation: 79983

@ECHO OFF
SETLOCAL
(
for /f "delims=" %%a in ('dir /b /a-d /s *') do (
 for /f "tokens=1,2delims= " %%w in ('dir /tw "%%a"^|findstr /v /b /c:" "') do (
  for /f "tokens=1,2delims= " %%c in ('dir /tc "%%a"^|findstr /v /b /c:" "') do echo %%c %%d,%%w %%x,%%a
  )
 )
)>u:\z.txt

GOTO :EOF

Produces output file u:\z.txt

execute a bare directory-list without directorynames but with all subdirectories, assigning each filename in turn to %%a.

Then run two standard dir listings on the name in %%a, the first for the last-write time and the second for the created time, with the second listing performed with the metavariables %%w and %%x in-context.

Filter each output using findstr to find lines that do not (/v) begin (/b) with the constant string "a single space" - which excludes all lines except the report on the file in %%a.

Then bang out just the first 2 tokens using spaces as delimiters.

Note that the parentheses surrounding the entire for statement allow the entire output to be redirected to a new file (replacing any existing file - change > to >> to append to an existing file (or create one if there's no existing file))

The caret before the pipe escapes the pipe so that cmd will interpret it as part of the command (in single quotes) to be executed, not part of the for.

Upvotes: 3

Related Questions