BATCH - 移动超过5分钟的文件

时间:2014-01-02 16:22:55

标签: batch-file

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

@echo off

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

move %%~nf.log \Procesados

)

exit

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

此批处理将继续运行,直到您停止运行,如果发现文件早于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