使用ROBOCOPY
AFAIK,不可能比一天更精确。
但是,可以使用其他两种方法获得更精细的信息。
DIR /o:d /a:-d
将当前目录的文件从最新到最旧排序,并将任何目录排除在列表之外。
要反转列表以使其从最旧到最新,请更改/o:d
为/o:-d
。
此外,该FOR
语句可以做同样的事情。
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
set count=0
:: If some other process left %tmp%\temp.txt, delete it.
if exist %tmp%\temp.txt del %tmp%\temp.txt
for %%x in (*.*) do (
set /a count=!count!+1
:: Capture Size
set size=000000%%~zx
:: Capture Date and Time
set td=%%~tx
:: Turn Date into YYYY/MM/DD format
set dd=!td:~6,4!/!td:~0,5!
:: Set tt=hour of day
set tt=!td:~11,2!
:: Turn AM/PM time into 24 hour day time
if !td:~-2!==PM set /a tt=!tt!+12
:: Add :Minutes to time
set tt=!tt!:!td:~-5,2!
:: Append Size Date Time FileName to temp.txt
call echo !size:~-5! !dd! !tt! %%x>>%tmp%\temp.txt
rem :: Create variable size[n] and set it to: Size Date Time FileName
rem call set size[!count!]=!size:~-5! !dd! !tt! %%x
)
echo.
echo Size Date Time FileName
echo ===== ========== ===== ===============
::
:: Alternate 1: Replacing the Append line to `temp.
:: :: Print Array into %tmp%\temp.txt
:: for /l %%x in (1 1 %count%) do (
:: :: Pipe variable into a file
:: echo !size[%%x]!>>%tmp%\temp.txt
:: )
::
:: Alternate 2: Another way to iterate through the array size[n]
:: :loop
:: set /a ctr=%ctr%+1
:: echo !size[%ctr%]!
:: if %ctr% lss %count% goto loop
::
:: Sort temp.txt, starting at the 6th character (the date).
type %tmp%\temp.txt | sort.exe /+6
del %tmp%\temp.txt
echo.
上面的代码并不像看起来那么长和复杂。大部分都是简单的注释,将近一半占用了代码。其余大部分是冗余代码,仅用于显示