Page 2 of 2 <12
Topic Options
#53066 - 2001-01-16 12:11 AM Re: Help! Cannot get "dynamic" date file-delete script to work...
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Hi there again!

Haha... well, i'm sure i'll come up with something to work on

Sure! we just have to make sure everyone has your homepage address right!

...and DAMN that smilie in the code

Oh, one other thing to mention is that when (at least myself) working with scripts, one could always have a commented "development" version, and another, less bulky script that you actually use. One just have to make sure the revisions are right though. No compiler is getting rid of the comments here

[This message has been edited by masken (edited 15 January 2001).]

_________________________
The tart is out there

Top
#53067 - 2001-01-16 12:51 AM Re: Help! Cannot get "dynamic" date file-delete script to work...
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Yeah, I was thinking about a posting the other scripts on my homepage in duplicate also. One with a lot of spaces and comments and one crunched up.

b.t.w. if you're gonna implement the script above in the real environment don't forget to remove the 'BREAK ON'. If you leave it in the script, users can stop (exit) the scipt by pushing CTRL-Break.

------------------
Greetz,

Roger the Young
------------------------
The code is out there...
------------------------

_________________________
The Code is out there

Top
#53068 - 2001-04-05 08:06 PM Re: Help! Cannot get "dynamic" date file-delete script to work...
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

We look also to the script (reason was topic http://kixtart.org/board/Forum2/HTML/001458.html )
We found some possible problems:


  • missing DIM statement. we think DrillSergeant was using an empty
    array element to stop the WHILE/LOOP
  • missing position of GOSUB "DO_LINE". we found "O_LINE". :D
    was interpretated as smile.
  • by calculation of a logfile an endless loop can be created.
    advise: append data to an existing file. all line has a date/time stamp.

For this reason we rewrite some code, which gives you information
about:


  • how much files were skipped or deleted.
  • how can I debug it.

An example of the logfile output by running for the following
directories: c:\winnt\help + c:\windows\help

code:

2001/04/05 04:40:15 delete 'c:\winnt\help\31users.FTS' (2001/03/03 05:24:09 size=76800 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\31users.hlp' (1996/10/14 03:38:00 size=58591 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.FTS' (2001/03/03 05:24:08 size=94720 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.hlp' (1996/10/14 02:38:00 size=32359 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.chm' (2001/01/14 13:47:18 size=21705 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.cnt' (2001/01/14 14:35:02 size=121 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.hlp' (2001/01/14 14:35:02 size=16804 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.cnt' (1996/10/14 03:38:00 size=502 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.hlp' (1996/10/14 03:38:00 size=12643 older 3 days)
.....
2001/04/05 04:40:15 delete 'c:\winnt\help\wangshl.cnt' (1996/10/14 02:38:00 size=102 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wangshl.hlp' (1996/10/14 02:38:00 size=8509 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.cnt' (1996/10/14 02:38:00 size=1888 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.hlp' (1996/10/14 02:38:00 size=26793 older 3 days)

An example of the screen output:

code:

check directory 'c:\windows\help'
check directory 'c:\winnt\help'

Informative DELETION: process completed. 112 files deleted + 2 files skipped.

directories checked:
'c:\windows\help'
'c:\winnt\help'
debug output: 'c:\temp\deletion_debug.txt'


The debug output looks:

code:

days 3
current date 2001/04/05
compare date 2001/04/02

check directory 'c:\windows\help'
check directory 'c:\winnt\help'
2001/04/05 04:40:15 delete 'c:\winnt\help\31users.FTS' (2001/03/03 05:24:09 size=76800 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\31users.hlp' (1996/10/14 03:38:00 size=58591 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.FTS' (2001/03/03 05:24:08 size=94720 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.hlp' (1996/10/14 02:38:00 size=32359 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.chm' (2001/01/14 13:47:18 size=21705 older 3 days)
-skip- 'c:\winnt\help\accessib.cnt'
-skip- 'c:\winnt\help\accessib.hlp'
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.cnt' (1996/10/14 03:38:00 size=502 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.hlp' (1996/10/14 03:38:00 size=12643 older 3 days)
.....
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocx.cnt' (1996/10/14 02:38:00 size=100 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocx.hlp' (1996/10/14 02:38:00 size=19229 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocxd.cnt' (1996/10/14 02:38:00 size=4415 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocxd.hlp' (1996/10/14 02:38:00 size=291485 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangshl.cnt' (1996/10/14 02:38:00 size=102 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wangshl.hlp' (1996/10/14 02:38:00 size=8509 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.cnt' (1996/10/14 02:38:00 size=1888 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.hlp' (1996/10/14 02:38:00 size=26793 older 3 days)


Our code is:

code:

;
; NT/95 delete files older then specified number of days - Kixtart 3.62, 3.63, 4.00
;
; (c) drillsergeant, mca - 2001
;
; vs 1.01 - program
;
; 1.00 (20010115) original version
; 1.01 (20010401)
;
CLS
BREAK on
FLUSHKB
MD "c:\temp"

IF (Len(@wksta) <> 0)
$wksta=@wksta
ELSE
$wksta="unknown"
ENDIF

; ---------------------------------------------------------------------------
; - site defined settings -
; ---------------------------------------------------------------------------

$debug_mode="yes" ; - yes/no -
$debug_file="c:\temp\deletion_debug.txt" ; - c:\temp\deletion_debug.txt = file
; - CON = means output to user screen

$days = 7 ; - delete files older than specified number of days -
$log_file="c:\temp\deletion_"+$wksta+".log" ; - append to this file -

$max_directories=2
DIM $remove_dir[$max_directories+1]
$remove_dir[1] = "c:\test1"
$remove_dir[2] = "c:\test2"

; ---------------------------------------------------------------------------
; - main program by DrillSergeant / MCA -
; ---------------------------------------------------------------------------

$temp_file="c:\temp\deletion.tmp"
$log_file=LCASE($log_file)
;
IF ($debug_mode = "yes")
DEL $debug_file
IF ReDirectOutput($debug_file)
ENDIF
ENDIF

; ---------------------------------------------------------------------------
; - Here you control whether files in subdirectories should be
; - or excluded, with the switch "/s".
; - The "/b" switch stands for "base notation", (which excludes
; - everything but the filename), don't change this one!
; ---------------------------------------------------------------------------

GOSUB "calculate_date"
?
IF Open(2,"$log_file",5)
ENDIF
;
$count_skipped=0
$count_delete=0
;
$i = 1
WHILE ($i <= $max_directories)
IF Close(1)
ENDIF
DEL $temp_file
? "check directory '"+$remove_dir[$i]+"'"
$command = '%comspec% /c dir "'+$remove_dir[$i]+'" /s /b >'+$temp_file
SHELL $command
IF (Open(1,$temp_file,2) = 0)
$line = ReadLine(1)
WHILE @error = 0
GOSUB "check_file"
$line = ReadLine(1)
LOOP
ENDIF
$i = $i + 1
LOOP
IF Close(1)
ENDIF
IF Close(2)
ENDIF
IF (Exist($temp_file) = 1)
DEL $temp_file
ENDIF
IF ReDirectOutput("CON")
ENDIF
? "Informative DELETION: process completed. "+
$count_delete+" files deleted + "+
$count_skipped+" files skipped."
?
? "directories checked: "
$i=1
WHILE ($i <= $max_directories)
? " '"+$remove_dir[$i]+"'"
$i=$i+1
LOOP
IF ($debug_mode = "yes")
? "debug output: '"+$debug_file+"'"
ENDIF
EXIT

; ------------------------------------------------------------------------
; - calculate the date (minus $days) by DrillSergeant - -
; ------------------------------------------------------------------------

:calculate_date
$cury = @year
$curm = @monthno
$curd = @mdayno
IF $curm < 3
$curm = $curm + 12
$cury = $cury - 1
ENDIF
$curint = $curd + ( 153 * $curm - 457 ) / 5 + 365 * $cury + $cury / 4 - $cury / 100 + $cury / 400 - 306
$myz = $curint - $days + 306
$myh = 100 * $myz - 25
$mya = $myh / 3652425
$myb = $mya - $mya / 4
$rd_year = (100 * $myb + $myh) / 36525
$myc = $myb + $myz - 365 * $rd_year - $rd_year / 4
$rd_month = (5 * $myc + 456) / 153
$rd_day = $myc - (153 * $rd_month - 457) / 5
IF $rd_month > 12
$rd_year = $rd_year + 1
$rd_month = $rd_month - 12
ENDIF
IF Len("$Rd_Month") = 1
$rd_month = "0" + "$Rd_Month"
ENDIF
IF Len("$Rd_Day") = 1
$rd_day = "0" + "$Rd_Day"
ENDIF
$compare_date = "$Rd_Year/$Rd_Month/$Rd_Day"
;
IF ($debug_mode = "yes")
? "days "+$days
? "current date "+@date
? "compare date "+$compare_date
ENDIF
RETURN

; ------------------------------------------------------------------------
; - check file for yes/no for deletion by DrillSergeant / MCA -
; ------------------------------------------------------------------------

:check_file
$time = GetFileTime($line)
IF ($time > "")
IF (Substr($time,1,10) < $compare_date)
$log_info=@date+" "+@time+" delete '"+$line+"'"+
" ("+GetFileTime($line)+
" size="+GetFileSize($line)+
" older "+$days+" days)"
IF WriteLine(2,$log_info+Chr(13)+Chr(10))
ENDIF
IF ($debug_mode = "yes")
? $log_info
ELSE
DEL $line ; <--------------------- delete files ------
ENDIF
$count_delete=$count_delete+1
ELSE
$log_info=" -skip- '"+$line+"'"
IF ($debug_mode = "yes")
? $log_info
ENDIF
$count_skipped=$count_skipped+1
ENDIF
ENDIF
RETURN


This please of code you can modify (site defined settings):

code:

$debug_mode="yes" ; - yes/no -
$debug_file="c:\temp\deletion_debug.txt" ; - c:\temp\deletion_debug.txt = file
; - CON = means output to user screen

$days = 7 ; - delete files older than specified number of days -
$log_file="c:\temp\deletion_"+$wksta+".log" ; - append to this file -

$max_directories=2
DIM $remove_dir[$max_directories+1]
$remove_dir[1] = "c:\test1"
$remove_dir[2] = "c:\test2"



Greetings.

btw: change $debug_mode="yes" to "no" for really
delete files.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#53069 - 2001-04-07 12:22 AM Re: Help! Cannot get "dynamic" date file-delete script to work...
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Hi again. See here for more info. I've copy-pasted the scipt that DrillSergeant and I made, this is the code that actually use, and it works...? Thos smilies are really annoying when you UBB Code it to "code"...

[This message has been edited by masken (edited 06 April 2001).]

_________________________
The tart is out there

Top
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.086 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org