Bullu Ulu
Bullu Ulu

Reputation: 51

How to get creation date of file on Windows command line?

I am currently using the following command to get the last modification time of files with a given pattern.

for /r C:\ %F in ("*.txt") do @echo "%~nxF", "%~tF"

How do I get the creation date instead?

Upvotes: 5

Views: 27632

Answers (2)

user12077603
user12077603

Reputation: 1

for /r D:\MyFolder %F in ("PartOfFileName*.ZIP") do SET FileNameCreated=%~tF
echo Minute = %FileNameCreated:~14,2%
echo Hour   = %FileNameCreated:~11,2%
echo AM/PM  = %FileNameCreated:~17,2%
echo Day    = %FileNameCreated:~0,2%
echo Month  = %FileNameCreated:~3,2%
echo Year   = %FileNameCreated:~6,4%

Upvotes: -1

npocmaka
npocmaka

Reputation: 57252

@echo off
for /f "skip=5 tokens=1,2,4,5* delims= " %%a in ('dir  /a:-d /o:d /t:c') do (
    if "%%~c" NEQ "bytes" (
        echo(
        @echo file name:     %%~d
        @echo creation date: %%~a
        @echo creation time: %%~b
        echo(

    )
)

But it depends on time settings.Another way is to use WMIC or embedded in bat jscript or vbscript or powershell.

EDIT (with WMIC - not avaialable in home editions of windows , but does not depend on time settings):

@echo off
set "target_dir=C:\some_dir"

for /f "tokens=2 delims=:" %%d in ("%target_dir%") do (
 set "data_path=%%d"
)
set data_path=%data_path:\=\\%\\
echo %data_path%

pushd %target_dir%

WMIC DATAFILE WHERE "PATH='%data_path%'" GET CreationDate,Caption

Upvotes: 6

Related Questions