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:jscript "%~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); } |
Recent Comments