Fauzan Zharfan
Fauzan Zharfan

Reputation: 47

Dir command : How to show only the date created file and created file .txt out of it

I know that dir /b shows only the file name. and dir /b /o:-d shows only the file name and sort by it by last date.

Is it possible to call dir, that only shows the file created date only (not showing sizes or names) and created a .txt files out of it?

the expected result is like this

28/06/2019 13:13 
28/06/2019 12:12
28/06/2019 11:11 
....

Upvotes: 1

Views: 17652

Answers (2)

aschipfl
aschipfl

Reputation: 34899

The dir command displays the last modification date/time as per default. To change to the creation date/time you need to add the /T:C option. To return the date/time values only use a for /F loop in a similar way as shown in Stephan's answer:

for /F "tokens=1,2 eol= " %I in ('dir /A:-D /O:-D /T:C *.*') do @echo/%I  %J

The eol option is set to a SPACE in order to exclude lines that begin with that character, because this applies to the introduction and summary lines, which we do not want. This method does not rely on filtering by a locale-dependent character.

(If you want to use this code in a , change every % to %%.)


For the last modification date you can simply omit the /T:C part. Alternatively you could use a simple for loop if you do not need the date/time values to be sorted (descendingly):

for %I in (*.*) do @echo/%~tI

The ~t modifier returns the last modification date/time.

Regard that both of the above approaches return the date/time values in a locale-dependent manner.

Upvotes: 4

Stephan
Stephan

Reputation: 56165

You can not do that with dir alone, but you can postprocess it's output with a for /f loop:

for /f "tokens=1,2" %a in ('dir /a-d /o-d') do @echo %a %b|find ":"' 

Note: this is command line syntax. For use in a batch file use %% instead of %

dir /a-d shows files only (no folders).
|find ":" shows only lines that have a colon (as in time 12:34), suppressing the summary lines.
"tokens=1,2" takes the first two "words" (delimited by spaces or tabs), so the date (first token, goes to %a) and the time (second token, goes to %b).

Upvotes: 3

Related Questions