banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

DIR命令无法获得精确到秒的问题

DIR 命令无法获得精确到秒的问题

方法一,dir 命令只能到分钟,如果需要到秒,建议改用 forfiles 命令 REM "delims=" is required to avoid stripping AM/PM for /f "delims=" %%i in ('"forfiles /p C:\Users\limc /m *.bat /c "cmd /c echo @fdate @ftime" "') do set modif_time=%%i echo %modif_time% 参考 https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc753551(v=ws.11)?redirectedfrom=MSDN

方法二,用 VBS 的 FileSystemObject 方式解决

@set @n=0/*&echo off
dir /a-d/s/b|Cscript -nologo -e "%~f0" > 1.txt
pause&exit /b */
var fso=new ActiveXObject('scripting.FileSystemObject');
while(!WSH.StdIn.AtEndOfStream)
{
file=fso.GetFile(WSH.StdIn.ReadLine());
t=new Date(file.DateCreated);
t1 = t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
WSH.Echo(file + "\t" + t1);
}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.