Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Error using DELOLDER Script to delete old files  (Read 6659 times)

0 Members and 1 Guest are viewing this topic.

akosz

  • Guest
Error using DELOLDER Script to delete old files
« on: July 06, 2006, 02:09:03 PM »
i don't know if anyone here has ever used the DELOLDER script found on http://www.ss64.com/ntsyntax/, but basically it deletes all files older than a certain number of days.  for example:

C:\> DELOLDER 90 "C:\TEMP\*"

will delete anything in C:\TEMP older than 90 days old.  this works on every server we have except for one and i can't figure out why.

i've narrowed down the problem to one line.  here's what happens when i set the echo on for that line.  my file variable seems to get lost.

---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---

SERVER_A (BAD)

C:\ORAMAINT>delolder 120 "C:\test\*"

FOR /f "tokens=*" %G IN ('XCOPY "c:\test\*" /D:03-08-2006 /L | FIND "\"') DO IF """=="%G" (GOTO :eof)


---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---

SERVER_B (GOOD)

C:\ORAMAINT>delolder 120 "C:\test\*"

FOR /f "tokens=*" %G IN ('XCOPY "C:\test\*" /D:03-08-2006 /L | FIND "\"') DO IF "C:\test\poop.txt"=="%G" (GOTO :eof)


---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---

both servers are windows 2003.  there's got to be some setting or something that i'm missing, but i think i'm staring at it too hard.

the scripts are in a zip file here:

http://www.ss64.com/ntsyntax/delolder.zip

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Error using DELOLDER Script to delete old file
« Reply #1 on: July 07, 2006, 06:04:36 AM »
The technique for aging files is actually quite clever. Unfortunately the truckload of supporting batch code is enough to choke a horse.

Best I could come up with is that this is the line in question:

FOR /f "tokens=*" %%G IN ('XCOPY %v_source% /D:%v_mm_str%-%v_dd_str%-%v_yy_int% /L ^| FIND "\"') DO IF %1=="%%G" (GOTO :eof)

Since there is no error in the code, check out the data. Run the XCOPY with the /d and /l switches at the command prompt and check the results. Turn ECHO ON so you can see what's passed to the subprograms and what data is returned.

Date calcs in batch seem to be this weeks hot topic. Given a choice, use one of the Windows scripting languages. They all have functions which are designed for just this purpose. Batch code is a command language not a programming language.

 8-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

akosz

  • Guest
Re: Error using DELOLDER Script to delete old file
« Reply #2 on: July 10, 2006, 09:23:57 AM »
the xcopy seems to work fine, but when i set ECHO on in the last line...


:s_match_older
echo FOR /f "tokens=*" %%G IN ('XCOPY %v_source% /D:%v_mm_str%-%v_dd_str%-%v_yy_int% /L ^| FIND "\"') DO IF %1=="%%G" (GOTO :eof)
DEL %1

it throws a double quote in where there should be a file name.  not only should there be a file name there instead, but the double quote screws up the whole line because it's looking for an "ending" double-quote to pair up with the extra one.

C:\ORAMAINT>DELOLDER 20 "C:\test\*.*"
FOR /f "tokens=*" %G IN ('XCOPY "C:\test\*.*" /D:06-20-2006 /L | FIND "\"') DO IF """=="%G" (GOTO :eof)

so:
• it's not the code (because the SAME code works on other servers).
• it's not the xcopy.

there's got to be some setting that's different on this server than the others, but i hav eno idea what it could be.


Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Error using DELOLDER Script to delete old file
« Reply #3 on: July 10, 2006, 11:22:42 AM »
Actually I meant to turn ECHO ON in the first line of DELOLDER.CMD. Using ECHO on the FOR line turns the statement into a ECHO instruction with FOR as a literal.

The only settings I'm aware of for the cmd processor are enableextensions and enabledelayedexpansion, both of which can be set within the batch file. Since the author saw no need to turn them on, it's doubtful they're needed.

Without knowing the data you're working with it's difficult to debug. Adding to the difficulty are the calls to subprograms (DateMath and GetDate) where data gets passed around. With ECHO ON (you may also have to turn on ECHO in the subprograms), you should be able to see how each statement is resolved. Work backwards to determine where the variables got their values from.

Considering that this works on other machines, try concentrating on unexpected data on this one machine.

Good luck.  8-)





The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein