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

17,095
@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
Share:
17,095

Related videos on Youtube

Bullu Ulu
Author by

Bullu Ulu

Updated on June 04, 2022

Comments

  • Bullu Ulu
    Bullu Ulu almost 2 years

    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?

  • jeb
    jeb over 4 years
    The question already described the %~t and that it returns the last modification time but NOT the requested creation timestamp
  • user12077603
    user12077603 over 4 years
    Just figured it out. Corrected now. Sorry about that!
  • jeb
    jeb over 4 years
    It still doesn't answer the question. %~tF contains the LAST MODIFICATION timestamp not the CREATION timestamp. It's not possible to get that timestamp with FOR-variable modifiers. See the answer of @npocmaka
  • Dominic Grenier
    Dominic Grenier about 3 years
    Just a heads up to anyone who ends up here and figure they want to extract date using this method. The string extraction arguments are not right for my machine. With the YYYY-MM-DD HH:MM format it is y=0,4,m=5,2,d=8,2,h=11,2,m=14,2 Where the first number is cardinal position of the first character and second is quantity of characters including first.