Click here to Skip to main content
16,011,538 members
Home / Discussions / System Admin
   

System Admin

 
GeneralFTP login Pin
rapace18-Feb-05 7:46
rapace18-Feb-05 7:46 
GeneralRe: FTP login Pin
Mekong River28-Feb-05 5:01
Mekong River28-Feb-05 5:01 
GeneralRe: FTP login Pin
rapace28-Feb-05 5:28
rapace28-Feb-05 5:28 
GeneralRe: FTP login Pin
Mekong River26-Feb-06 0:11
Mekong River26-Feb-06 0:11 
Generalbatch file in dos Pin
trupgmtuf18-Feb-05 7:39
susstrupgmtuf18-Feb-05 7:39 
GeneralRe: batch file in dos Pin
Roger Wright18-Feb-05 22:28
professionalRoger Wright18-Feb-05 22:28 
GeneralRe: batch file in dos Pin
Mekong River28-Feb-05 5:13
Mekong River28-Feb-05 5:13 
GeneralRe: batch file in dos Pin
markar18-Mar-05 16:44
markar18-Mar-05 16:44 
OK - this is a bit longer than I expected, but it does the job and shows you the techniques to extend it. This code does assume that you are running WinNT 4 or later. I have only tested it on XP.

You can find lots of info about building batch files in Windows NT Shell Scripting, by Tim Hill. A chapter of this book is available on the Code Project web site.

Mark

=============== batch script ======================================

@echo off
setlocal enabledelayedexpansion
::===============================================================
:: Oldfiles.bat
:: Usage: Oldfiles [minutes]
:: Arguments: Minutes - the maximum age of files
::
:: This script looks through the files in the current directory
:: (and its sub-directories) and lists all the files that are older
:: than the number of minutes entered on the command line.

:: Specify the number of minutes to check for
if [%1]==[] (
set /a AGELIMITMIN = 60
) else (
rem This should fail if %1 is not a valid number
set /a AGELIMITMIN = %1
)

rem Note that %TIME% is in 24 hour format, unlike the timestamp on files
echo %TIME%
:: format hh:mm:ss.ss - 24hr clock
for /f "tokens=1-3 delims=: " %%a in ("%TIME%") do (
set CHH=%%a & set CMIN=%%b & set CSS=%%c
)

echo %DATE%
:: format DDD MM/DD/YYYY
for /f "tokens=1-4 delims=/ " %%a in ("%DATE%") do (
set WDAY=%%a & set CMON=%%b & set CDD=%%c & set CYYYY=%%d
)

::strip any leading zeros so the math will work (leading zeros imply octal)
::hours don't have leading zeros, just a leading space
if %CSS% LSS 10 set CSS=%CSS:~1,1%
if %CMIN% LSS 10 set CMIN=%CMIN:~1,1%

rem knock off any leading or trailing spaces
set /a CHH = CHH
set /a CDD = CDD
set /a CMON = CMON

::calculate the number of minutes since the start of the month
set /a TMSTAMP = CDD*24*60 + CHH*60 + CMIN

set /a LIMITSTAMP = TMSTAMP - AGELIMITMIN

echo CurMin = %TMSTAMP% LIMIT = %LIMITSTAMP%

rem here's where we set the time period of 1 hour
if %LIMITSTAMP% LSS 0 (
echo This program does not work in the first
echo %AGELIMITMIN% minutes of a month!!
echo Quitting
echo.
goto :EOF
)


rem echo %HH% %MIN% %SS%
rem echo %WDAY% %DD%/%MON%/%YYYY%

::loop recursively through all the files in the current directory
:: and all lower directories
for /r %%I in (*.*) do (
rem echo %%~tI %%I
set OLD=TRUE

rem MM/DD/YYYY HH:MM PM
call :PARSEFILETIME %%~tI

set /a FTMSTAMP = DD*24*60 + HH*60 + MIN

rem Find any files that are older than the limit
rem these checks assume that AGELIMIT is less than a month
if !YYYY! GEQ !CYYYY! (
if !MON! GEQ !CMON! (
if !FTMSTAMP! GEQ !LIMITSTAMP! (
rem file is newer than the cutoff time
set OLD=FALSE
)
)
)
if [!OLD!]==[FALSE] (
echo %%I is new enough. %%~tI !HH!:!MIN! !FTMSTAMP!
) else (
rem Here is where you would delete old files
rem or you could accumulate the names in a file
rem for later deletion

rem echo %%I is too old and will be deleted.
)
)


::Now loop through the directories
for /r /d %%I in (*.*) do (
rem echo %%~tI %%I
set OLD=TRUE

rem MM/DD/YYYY HH:MM PM
call :PARSEFILETIME %%~tI

rem echo !YYYY!/!MON!/!DD! !HH!:!MIN!

set /a FTMSTAMP = DD*24*60 + HH*60 + MIN

rem Find any directories that are older than the limit
rem these checks assume that AGELIMIT is much less than a month
if !YYYY! GEQ !CYYYY! (
if !MON! GEQ !CMON! (
if !FTMSTAMP! GEQ !LIMITSTAMP! (
rem file is newer than the cutoff time
set OLD=FALSE
)
)
)

rem echo %%I %%~tI !FTMSTAMP!

if [!OLD!]==[FALSE] (
echo %%I is new enough. %%~tI !HH!:!MIN! !FTMSTAMP!
) else (
rem Here is where you would delete old directories
rem echo %%I is too old and will be deleted.
)
)

goto :EOF

::================================================
:: PARSEFILETIME
:: Arguments: Timestamp
:: format MM/DD/YYYY HH:MM PM (format from %~t)
:: Returns: sets variables MON, DD, YYYY, HH, MIN
::================================================
:PARSEFILETIME
set RET=FALSE
rem Should do some checks for valid format
for /f "tokens=1-6 delims=:/ " %%a in ("%*") do (
set MON=%%a
set DD=%%b
set YYYY=%%c
set HH=%%d
set MIN=%%e
set AMPM=%%f
)


rem set /a math thinks leading zeros imply octal numbers,
rem so get rid of them
if %MON% LSS 10 set MON=%MON:~1,1%
if %DD% LSS 10 set DD=%DD:~1,1%
if %HH% LSS 10 set HH=%HH:~1,1%
if %MIN% LSS 10 set MIN=%MIN:~1,1%

rem echo !MON! !DD! !YYYY! !HH! !MIN!

rem deal with 12:30 am = 00:30 hrs and 12:30 pm = 12:30 hrs
if !HH! EQU 12 set /a HH=!HH! - 12
if [%AMPM%]==[PM] set /a HH=!HH! + 12

rem Should return false if format is wrong
set RET=TRUE
goto :EOF

GeneralNeed help...Email Server MS Exchange Pin
enjoycrack17-Feb-05 0:43
enjoycrack17-Feb-05 0:43 
GeneralRe: Need help...Email Server MS Exchange Pin
Mike Dimmick17-Feb-05 1:48
Mike Dimmick17-Feb-05 1:48 
QuestionVirtual Drive ? Pin
srieen15-Feb-05 17:25
srieen15-Feb-05 17:25 
AnswerRe: Virtual Drive ? Pin
Mekong River26-Feb-05 11:21
Mekong River26-Feb-05 11:21 
GeneralRe: Virtual Drive ? Pin
srieen27-Feb-05 17:27
srieen27-Feb-05 17:27 
GeneralRe: Virtual Drive ? Pin
Mekong River27-Feb-05 20:44
Mekong River27-Feb-05 20:44 
GeneralTrap and remap a key for a specific application Pin
Berkelium15-Feb-05 6:24
Berkelium15-Feb-05 6:24 
GeneralRe: Trap and remap a key for a specific application Pin
Mekong River26-Feb-05 11:13
Mekong River26-Feb-05 11:13 
GeneralMs access close immediately Pin
Mekong River13-Feb-05 20:30
Mekong River13-Feb-05 20:30 
GeneralRe: Ms access close immediately Pin
Roger Wright18-Feb-05 22:56
professionalRoger Wright18-Feb-05 22:56 
GeneralRe: Ms access close immediately Pin
Mekong River26-Feb-05 11:09
Mekong River26-Feb-05 11:09 
GeneralVGA card and VGA built-in Pin
Mekong River11-Feb-05 14:48
Mekong River11-Feb-05 14:48 
GeneralRe: VGA card and VGA built-in Pin
Aryo Handono13-Feb-05 20:34
professionalAryo Handono13-Feb-05 20:34 
GeneralRe: VGA card and VGA built-in Pin
Mekong River26-Feb-06 15:34
Mekong River26-Feb-06 15:34 
GeneralRe: VGA card and VGA built-in Pin
raouls13-Feb-05 20:37
raouls13-Feb-05 20:37 
GeneralRe: VGA card and VGA built-in Pin
Mekong River26-Feb-06 15:35
Mekong River26-Feb-06 15:35 
GeneralRe: VGA card and VGA built-in Pin
albCode6-Jun-05 3:30
albCode6-Jun-05 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.