我一直在使用以下命令来获取文件日期。但是,自从我们移到另一台服务器(Windows Server2003)后,fileDate
变量就一直返回空值。
FOR /f %%a in ('dir myfile.txt^|find /i " myfile.txt"') DO SET fileDate=%%a
有没有其他更可靠的方法来获取文件日期?
发布于 2010-01-22 18:01:38
将%
更改为%%
以便在批处理文件中使用,对于%~ta
语法,请输入call /?
for %a in (MyFile.txt) do set FileDate=%~ta
示例输出:
for %a in (MyFile.txt) do set FileDate=%~ta
set FileDate=05/05/2020 09:47 AM
for %a in (file_not_exist_file.txt) do set FileDate=%~ta
set FileDate=
发布于 2015-05-13 00:05:02
你可以的
forfiles /M myfile.txt /C "cmd /c echo @fdate @ftime"
发布于 2018-01-30 18:52:51
使用批处理文件获取文件属性的有用参考,包括上次修改时间:
FOR %%? IN ("C:\somefile\path\file.txt") 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 Drive and Path : %%~dp?
ECHO Drive : %%~d?
ECHO Fully Qualified Path : %%~f?
ECHO FQP in 8.3 notation : %%~sf?
ECHO Location in the PATH : %%~dp$PATH:?
)
https://stackoverflow.com/questions/2111333
复制相似问题