0
FOR %%? IN (file_to_be_queried) DO (
    ECHO File Name Only       : %%~n?
    ECHO File Extension       : %%~x?
    ECHO Name in 8.3 notation : %%~sn?
    ECHO File Attributes      : %%~a?
    ECHO Located on Drive     : %%~d?
    ECHO File Size            : %%~z?
    ECHO Last-Modified Date   : %%~t?
    ECHO Parent Folder        : %%~dp?
    ECHO Fully Qualified Path : %%~f?
    ECHO FQP in 8.3 notation  : %%~sf?
    ECHO Location in the PATH : %%~dp$PATH:?
)

我在http://www.robvanderwoude.com/battech_fileproperties.php看到了这个。

但是当我尝试应用它时,在循环中我使用“set”

SET datetime_t = %%~t?

回显 datetime_t %datetime_t% > result.txt

在文件里面只显示

datetime_t
datetime_t
datetime_t
datetime_t

这个变量发生了什么?它是空的吗?

4

1 回答 1

1

尝试这个:

setlocal enabledelayedexpansion
Rem Above is required for this to work

FOR %%? IN (file_to_be_queried) DO (
ECHO File Name Only       : %%~n?
ECHO File Extension       : %%~x?
ECHO Name in 8.3 notation : %%~sn?
ECHO File Attributes      : %%~a?
ECHO Located on Drive     : %%~d?
ECHO File Size            : %%~z?
ECHO Last-Modified Date   : %%~t?
ECHO Parent Folder        : %%~dp?
ECHO Fully Qualified Path : %%~f?
ECHO FQP in 8.3 notation  : %%~sf?
ECHO Location in the PATH : %%~dp$PATH:?

SET datetime_t=%%~t?
Echo datetime_t !datetime_t! > result.txt
Rem Notice use of "!"
)

这应该可以正常工作。

莫娜

于 2013-11-11T10:38:29.663 回答