我有一个Windows框和一个包含这样的文件的文件夹:
2010-07-04 20:18 81 in01_Acct_20100704001.r 2010-07-07 05:45 165 in01_Acct_20100706001.r 2010-07-07 19:41 82 in01_Acct_20100707001.r 2010-07-07 10:02 81 in01_Acct_20100707002.r 2010-07-08 08:31 89 in01_Acct_20100708001.r 2010-07-10 04:51 82 in01_Acct_20100709001.r
我想使用一个批处理周期性地将所有这些文件移动到另外一个文件夹(即01_Acct_20100709001.r),因为这个文件有时还在被写入,移动它可能导致文件覆盖到下一个目标文件夹运行批处理,并导致文件内容丢失。
任何关于这种情况下的想法将不胜感激。
在这里发布suyao的答案:
for /F "skip=1" %f IN ('dir /TW /OD /AD /B') DO move %f wherever
简单的解释是DIR命令已经预先build立了datesorting。
/T (has W implied would work as well) sorts based on time Last Written /O sets the order, -D = By Date/Time, in reverse order /AD only entries that are NOT directories (hence files) /B returns simply the filename
“skip = 1”意味着代码应该忽略返回的最上面的一行,并且由于文件的sorting正确,这将是最近的文件。