【问题标题】:BATCH - Move files older than 5 minutesBATCH - 移动超过 5 分钟的文件
【发布时间】:2014-01-20 03:32:51
【问题描述】:

我想用超过 5 分钟的时间移动可执行文件。不知道如何比较文件的修改日期和系统日期。

@echo off

for %%f in (*.log) do ( 

move %%~nf.log \Procesados

)

exit

【问题讨论】:

  • 是否必须在批处理中?这在 Powershell 中会容易得多!
  • 这篇文章中可能有一些东西给你stackoverflow.com/questions/9922498/…
  • 当我为文件设置修改日期时,例如设置文件时间=%%~tf 变量文件时间为空,我无法比较

标签: batch-file


【解决方案1】:

一种方法是下载findutilscoreutils 然后这样做:

gnu_find . -type f -mmin +05 -exec cp "{}" c:\destination ;

这就是你所需要的。日期计算也得到了照顾。无需重新发明您自己的日期计算方法。

根据 OP 查询编辑:

在下面的示例中,FIND 搜索当前目录 (.) 中的所有文件

gnu_find . -type f -mmin +5 -exec cp "{}" C:\destination\folder ;

但是,您可以根据需要指定要搜索的目录:

gnu_find D:\source\folder -type f -mmin +5 -exec cp "{}" E:\destination\folder ;

要了解 FIND 实用程序的更多选项,请阅读此处.....

Read me-1

Read me-2

Read me-3

【讨论】:

  • 如果我想将文件从源目录移动到目标目录,命令应该是这样吗?
【解决方案2】:

此批处理将继续运行,直到您停止它,如果它发现文件比 Xtime 旧,它会将其移动到目标。 将批处理与 .log 文件放在同一文件夹中。

@echo off
setlocal enabledelayedexpansion

:Loop
set "Xtime=5"

For /F "tokens=2,* delims=:" %%a in ('echo %time%') Do set CurrTime=%%a
For %%a in (*.log) Do (
For /F "tokens=3 delims=: " %%b in ("%%~ta") Do (
set "Ftime=%%b"
set /a check = CurrTime - Ftime
IF !check! GEQ !Xtime! ( MOVE /Y %%~fsa path_to_destiantion_folder
) Else ( goto next )
)
)

:next
goto Loop

更改 Xtime 以满足您的需要。

CURTSEY: This thread

【讨论】:

  • 看起来这会失败,具体取决于时间格式。 24 小时对 12 小时制。
猜你喜欢
  • 1970-01-01
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-19
  • 1970-01-01
  • 2013-10-28
  • 2020-07-07
相关资源
最近更新 更多