在FOR命令中存储时间戳变量以执行操作

时间:2013-09-23 09:11:36

标签: batch-file

为什么我不能存储它?

FOR %%a IN ("some_file_path") DO (
    SET FileDateTime=%%~ta
    echo !FileDateTime!
)

输出是~ta

这也不起作用。

Setlocal EnableDelayedExpansion
FOR %%a IN ("some_file_path") DO (
    SET FileDateTime=!!~ta
)

2 个答案:

答案 0 :(得分:1)

此类代码有效

SETLOCAL EnableDelayedExpansion 
FOR %%a IN ("some_file_path") DO (
    ECHO %%a
    SET FileDateTime=%%~ta
    ECHO !FileDateTime!
)

答案 1 :(得分:1)

这些也应该有效:

A:

FOR %%a IN ("some_file_path") DO (
    SET FileDateTime=%%~ta
    call echo %%FileDateTime%%
)

B:

FOR %%a IN ("some_file_path") DO (
    SET FileDateTime=%%~ta
)
    echo %FileDateTime%
相关问题