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?
@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
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%
%~t
and that it returns the last modification time
but NOT the requested creation timestamp
%~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
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.
Commented
Feb 28, 2021 at 2:26