批处理 - xcopy 早于 x 分钟的文件

Batch - xcopy files older than x minutes

在 20 分钟的新文件创建时间后,我想将所有扩展名为 .txt 的文件从文件夹 New 复制到文件夹 Target。 (我想复制 olny 文件早于 20 分钟)

到目前为止,它看起来像这样:

set hh=%TIME:~0,2%
set mm=%TIME:~3,2%
set ss=%TIME:~6,2%

set /a sum_sec=%hh% * 3600 + %mm% * 60 + %ss% -300

set /a h=%sum_sec% / 3600
set /a m=(%sum_sec%/60) - 60 * %h%
set /a s=%sum_sec% - 60 * (%sum_sec%/60)
IF %h% LSS 10 set h=0%h%
IF %m% LSS 10 set m=0%m%
IF %s% LSS 10 set s=0%s%

set new_time=%h%:%m%:%s%

到目前为止,我只删除了超过 20 分钟的文件:

forfiles /P "C:\Users\Desktop\Start" /S /M *.txt /C "cmd /c if @ftime LSS %new_time% del /F /Q @path"

我现在的问题是如何在 20 分钟后将新文件从文件夹 New 复制到文件夹 Target

最佳成绩

检查FileTimeFilter.bat - 它能够按不同时间过滤文件conditions.So(它应该在同一目录中):

@echo off
for /f "tokens=* delims=" %%# in ('
  call FileTimeFiler.bat "New" -mm -20 -direction before -filetime created
') do (
   copy "%%~f#" "Target"
)

编辑。过滤 txt 文件

@echo off
for /f "tokens=* delims=" %%# in ('
  call FileTimeFiler.bat "New" -mm -20 -direction before -filetime created ^| findstr /e /i ".txt"
') do (
   copy "%%~f#" "Target"
)