修改了批处理文件根据日期复制文件 [英] Copying files based on date modified in batch file

查看:428
本文介绍了修改了批处理文件根据日期复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个目录复制到另一个文件使用DOS批处理脚本。我要复制的文件是4或3最新的文件。该数目将是静态的,但尚未确定。反正是有复制的基础上修改日期?

I am trying to copy files from one directory to another using a DOS batch script. The files I want to copy are the 4 or 3 latest files. That number will be static, but yet to be determined. Is there anyway to copy based on date modified?

感谢您

推荐答案

您可以:

1),在日期的降序修改 DIR 命令排序文件;

1) have the dir command sort files in the descending order of date modified;

2)使用 DIR 命令的输出在'for循环复制相应的文件;

2) use the output of the dir command in a `for loop to copy the corresponding files;

3)计数至3(或4)循环,以限制复制的文件的数量。

3) count to 3 (or 4) in the for loop to limit the number of files copied.

@ECHO OFF
SET "srcdir=D:\Source"
SET "tgtdir=D:\Target"
SET /A topcnt=3
SET /A cnt=0
FOR /F "tokens=*" %%F IN ('DIR /A-D /OD /TW /B "%srcdir%"') DO (
  SET /A cnt+=1
  SETLOCAL EnableDelayedExpansion
  IF !cnt! GTR !topcnt! (ENDLOCAL & GOTO :EOF)
  ENDLOCAL
  COPY "%srcdir%\%%F" "%tgtdir%"
)

这篇关于修改了批处理文件根据日期复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆