Outputting Creation date

September 30, 2011 at 03:17:38
Specs: Windows 7
I have the following line of batch code

<for /f "tokens=*" %a in ('dir /b /a-d /s 2^>NUL') do call :PROCESS "%a" %~ta>

This outputs a list of file names followed by there last modified date to the function process. I want to modify the line so that it outputs the file names and the creation date instead.

Any suggestions? Ive tried changing the end to %#~tc on the basis that I thought it might be using the dir parameter set but this doesnt work.

Can anyone help?

See More: Outputting Creation date

Report •

September 30, 2011 at 05:50:04
Add the /tc directly to the dir statement. Check out dir /?, you'll see that /t lets you chose which timestamp to use, creation, last access, or last written.

<for /f "tokens=*" %a in ('dir /b /a-d /s /tc 2^>NUL') do call :PROCESS "%a" %~ta>

Report •

September 30, 2011 at 08:18:55
It seems the me that the %~ta at the end of the statment is what is adding the date so I belive its this bit that needs to be either changed or removed. Adding /tc into the dir statments doesnt help. nothing other than file path is displayed.

(tried this by swapping out "do call process" with "do echo")

EDIT : It appears as though the /b in the dir is causing the date to be stripped off.. any suggestions how I can get the date added back on again?

Report •

September 30, 2011 at 09:29:04
I thought it might be using the dir parameter set but this doesnt work.
Nope. That command provides a path, and FOR performs its own file lookup, and grabs the modified date. I don't know of any command that shows the created date, outside of "DIR /TC".

Really, the Command Prompt itself has no concept of date, and neither do most of its commands. You might want to look at another, better scripting language. VBScript/JScript comes with all versions of Windows since NT4/Win98, and PowerShell is included with Win7/Server2008.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question