Sorry - I know very little about batch files.
http://lipas.uwasa.fi/~ts/http/http2.html#batch
I have files continually created in a directory - C:\ABC that I want
deleted periodically once they are older than a particular number of
hours. I wonder if anyone can help me with a batch file that will
delete files older than a specific number of minutes, by taking the
minutes argument from command line. So it would be run on commandline
as follows... like "clean C:\ABC X_MINUTES".
The essence of the task is to find out the timestamp X_MINUTES ago.
Then (not covered below) one compares the files' datestamps with that
value.
Please note. Followups narrowed down to alt.msdos.batch.nt only.
Also I'll assume XP. One always should specify one's OS when asking!
DRAFT:
147} What was the time 100 minutes ago?
@echo off & setlocal enableextensions
::
rem The 24h time format is assumed
rem as always is sensible in an international se
::
:: Get the current time: hour and minutes
for /f "tokens=1,2 delims=:" %%a in ('time /t') do (
set hhNow_=%%a
set mmNow_=%%b
)
:: Remove any leading zeros to avoid the octal trap
for /f "tokens=* delims=0" %%a in ('echo %hhNow_%') do set hhNow_=%%a
for /f "tokens=* delims=0" %%b in ('echo %mmNow_%') do set mmNow_=%%b
::
:: Current time in minutes since midnight
set /a mmSinceMidnight=60*%hhNow_%+%mmNow_%
::
:: Display
echo hhNow_ %hhNow_%
echo mmNow_ %mmNow_%
echo mmSinceMidnight %mmSinceMidnight%
::
:: How many minutes to calculate backwards?
set back_=0
set rollover=
if not "%~1"=="" set back_=%1
::
:: How many minutes since midnight was back minutes ago?
set /a backSinceMidnight=%mmsinceMidnight%-%back_%
if %backSinceMidnight% LSS 0 (
set /a backSinceMidnight=%backSinceMidnight%+24*60
set rollover=true
)
:: Display
echo backSinceMidnight %backSinceMidnight%
::
:: Convert the result to hours and minutes
set /a hhBack_=%backSinceMidnight%/60
set /a mmBack_=%backSinceMidnight%-60*%hhBack_%
:: Display
echo hhBack_ %hhBack_%
echo mmBack_ %mmBack_%
if defined rollover echo Yesterday
::
endlocal & goto :EOF
The output e.g.
C:\_D\TEST>cmdfaq 100
hhNow_ 9
mmNow_ 33
mmSinceMidnight 573
backSinceMidnight 473
hhBack_ 7
mmBack_ 53
All the best, Timo