3

I want to make a move executable files with more than 5 minutes. Do not know how to compare the modified date of the file VS the system date.

@echo off

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

move %%~nf.log \Procesados

)

exit
Mark
  • 3,332
  • 1
  • 19
  • 33
Alex Agrazal
  • 53
  • 2
  • 8
  • Does it *have* to be in Batch? This would be massively easier in Powershell! – RB. Jan 02 '14 at 16:27
  • there might be something in this post for you http://stackoverflow.com/questions/9922498/calculate-time-difference-in-batch-file – kenny Jan 02 '14 at 16:28
  • When I set the date modified for the file, e.g set filetime=%%~tf the variable filetime is empty, I can't compare – Alex Agrazal Jan 02 '14 at 16:39

2 Answers2

1

One way is to download findutils and coreutils then do this:

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

that's all you need. Date calculation is taken care of as well. No need to reinvent your own date calculation.

EDIT As per OP queries:

In below example FIND searches for all the files in current directory (.)

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

But, you can specify a directory to search as you wish:

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

To learn more options of FIND utility, read here.....

Read me-1

Read me-2

Read me-3

Sunny
  • 6,736
  • 10
  • 25
  • 47
0

This batch will keep running untill you stop it and if it finds a file is older than Xtime it moves it to a destination. Put the batch in the same folder with the .log files.

@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

change the Xtime to suit your needs.

CURTSEY: This thread

Sunny
  • 6,736
  • 10
  • 25
  • 47