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
Related videos on Youtube
Author by
Bullu Ulu
Updated on June 04, 2022Comments
-
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 over 4 yearsThe question already described the
%~t
and that it returns thelast modification time
but NOT the requestedcreation timestamp
-
user12077603 over 4 yearsJust figured it out. Corrected now. Sorry about that!
-
jeb over 4 yearsIt still doesn't answer the question.
%~tF
contains theLAST MODIFICATION timestamp
not theCREATION timestamp
. It's not possible to get that timestamp with FOR-variable modifiers. See the answer of @npocmaka -
Dominic Grenier about 3 yearsJust 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.