如何在Windows命令行上获取文件的创建日期?

时间:2014-07-24 08:26:27

标签: windows file batch-file

我目前正在使用以下命令获取具有给定模式的文件的最后修改时间。

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

如何获得创建日期呢?

2 个答案:

答案 0 :(得分:1)

@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(

    )
)

但这取决于时间设置。另一种方法是使用WMIC或嵌入bat jscript或vbscript或powershell。

编辑(使用WMIC - 在家庭版Windows中不可用,但不依赖于时间设置):

@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

答案 1 :(得分:-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%