Computing.Net > Forums > Disk Operating System > DELOLD.BAT crazy errors

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DELOLD.BAT crazy errors

Reply to Message Icon

Name: geoff
Date: August 3, 2003 at 15:17:53 Pacific
OS: Win NT Server SP6
CPU/Ram: 512 RAM PII 333
Comment:

Hello. Stock and PROVEN delete batch file to find files so many days old and delete except on this NT server

Error 1
=======
Caused by CODE:
================
set /A dd=%dd% - %OLDERTHAN%
set /A mm=%mm% + 0

Invalid number. Numeric contants are either decimal (17)
hexadecimal (0x11), binary (0b10001) or octal (021).

Reason: this occurs becasue month and day resolves to "02" or other with zero before digit; doesn't the SET /A clear this up?

If I remove the "0" before digit it works up to next error.
********************************************

ERROR 2
=======

Caused by CODE:
===============
for %%i in (*.*) do ( set FileName=%%i call :PROCESSFILE %%~ti
)

Need to get the full date to be used for parse and comparison later on?


For valid formats type CALL /? or FOR /?
The following usage of the path operator in batch-parameter
substitution is invalid: %~ti

Thanks in advance.


**************************************

:: --------DELOLD.BAT----------
@echo off
SET OLDERTHAN=%1
::if "%1" == "" goto SYNTAX
IF NOT DEFINED OLDERTHAN GOTO SYNTAX

for /f "tokens=2" %%i in ('date /t') do set thedate=%%i

set mm=%thedate:~0,2%
set dd=%thedate:~3,2%
set yyyy=%thedate:~6,4%

set /A dd=%dd% - %OLDERTHAN%
set /A mm=%mm% + 0

if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
if %mm%==12 goto SET31

goto ERROR

:SET31
set /A dd=31 + %dd%
goto DONE

:SET30
set /A dd=30 + %dd%
goto DONE

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29

:SET28
set /A dd=28 + %dd%
goto DONE

:SET29
set /A dd=29 + %dd%

:DONE
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%
::for %%i in (*.*) do (set FileName=%%i echo %%i)
for %%i in (*.*) do ( set FileName=%%i call :PROCESSFILE %%~ti
)

set mm=
set yyyy=
set dd=
set thedate=
goto EXIT

:SYNTAX
ECHO.
ECHO USAGE:
ECHO DELOLD X
ECHO Where X is the number of days previous to Today.
ECHO.
ECHO EX: "DELOLD 5" Deletes files older than 5 days.
PAUSE
GOTO EXIT

:PROCESSFILE
set temp=%1
set fyyyy=20%temp:~6%
set fmm=%temp:~0,2%
set fdd=%temp:~3,2%
if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%

:: +*************************************+
:: | This is where the files are deleted |
:: | Change the ECHO command to DEL to |
:: | delete. ECHO is used for test. |
:: +*************************************+
if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% (
ECHO %FileName%
)

set temp=
set fyyyy=
set fmm=
set fdd=

:EXIT

:: ----------END-DELOLD.BAT-------------



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: August 3, 2003 at 22:28:19 Pacific
Reply:

I see many errors on that batch file. The author used unproper ways to cut off any traling zeros on the date variables.

set /a mm = %mm% + 0

That will not work if %mm% is 08 or 09.

set /A dd=%dd% - %OLDERTHAN%

That might not work as expected either. Here is a proper way to cut any zeroes from the %dd% and %mm% variables, before any calculations are done:

if "%dd:~0,1%"=="0" set dd=%dd:~1%
if "%mm:~0,1%"=="0" set mm=%mm:~1%

Having found such basic erros, I did not bother to look at the rest of the code. I don't know where you got this, but I definitively think a batch writer should test his code better before publishing, specially when the script is for such a serious task. I would advise looking for a different solution for the problem instead of trying to fix this batch file. That is a well-known issue, and many solutions have already been developed.

By the way, you should report errors direcly to the author, if you feel like doing such thing.

I developed a solution based on batch scripting myself, but it is currently only compatible with Windows 2000 and XP. Besides, I recently encountered a bug and stopped improoving it, due to the existance of so many other solutions. Look at news:alt.msdos.batch for other solutions.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 2
Name: bitbyte
Date: August 4, 2003 at 05:31:28 Pacific
Reply:


if a batch only solution is not nessesary then try my lsfdt.com and delflist.com, you can use them in a batchfile to delete old files

see also OLDER2DA.BAT its an example to delete files oder than 2 days

all at my page http://plop.at



0

Response Number 3
Name: geoff
Date: August 4, 2003 at 09:54:09 Pacific
Reply:

Hello.

Actually, this is a widespread batch file and it got reviews for working out of the box? I have seen it on Computing.net also. Who knows but I almost have it where I need it.

Thanks for the code- I ended up using less elegant to accomplish. The one item I can't figure out or find correct syntax for is this

for %%i in (*.*) do ( set FileName=%%i call :PROCESSFILE %%~ti)

It gets the current directory filename, calls routine, and this is where I get stuck as I need to get the first part of the full directory/filename list with date for later comparison...is there a way to get this from the FOR loop variable? the code uses %%~ti

Directory of E:\temp

07/16/03 06:02p 245,760 admin.pst

So I would need the 07/16/2003

Thanks very much.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Epson Equity LT PC Anywhere for DOS



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: DELOLD.BAT crazy errors

using xcopy over a lan www.computing.net/answers/dos/using-xcopy-over-a-lan/15098.html

Checking Exit Status of Batch File www.computing.net/answers/dos/checking-exit-status-of-batch-file-/11962.html

problem with access to cdrom drive www.computing.net/answers/dos/problem-with-access-to-cdrom-drive/8320.html