#3595 - 2000-07-25 11:17 AM
Date check then delete
|
Anonymous
Anonymous
Unregistered
|
Hi,I want to do a date check (28th of the month) If it is the 28th, i want to delete the files older then a month. Any suggestions how to do this ? thx, Jasper
|
|
Top
|
|
|
|
#3597 - 2000-07-26 12:18 AM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
I've been trying to get something together but I keep running into the problem that the substr variables are strings.. and I can't seem to get them back to numeric.*stumped*
|
|
Top
|
|
|
|
#3598 - 2000-07-25 01:09 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
Arn't I the simpleton.. VAL should clear that up just fine... *grin*
|
|
Top
|
|
|
|
#3599 - 2000-07-25 01:13 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
Thanx for the quick response. My problem is that it are a lot of files.... Is it possible to make the script short ?Also, my knowledge of Kixtart isn't that great...so please give me an example of what you mean...
|
|
Top
|
|
|
|
#3600 - 2000-07-25 01:33 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
BREAK ON$file=c:\kix\kix32.exe $monthover=0 $date_old=getfiletime("$file") $year_old=VAL(substr($date_old,1,4)) $month_old=VAL(substr($date_old,6,2)) $day_old=VAL(substr($date_old,9,2)) IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old<12) $monthover=1 GOTO decided ENDIF IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old=12) AND (@monthno>1) $monthover=1 GOTO decided ENDIF IF ((@monthno-$month_old)>1) $monthover=1 GOTO decided ENDIF IF ((@monthno-$month_old)=1) $monthover=1 GOTO decided ENDIF EXIT :decided ; "Commands to delete the file here" EXIT To read multiple files just do a dir /b in the directory and create a textfile - and read the resulst with a loop.
|
|
Top
|
|
|
|
#3602 - 2000-07-25 02:17 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
Nope.... The files are also in subfolders ! That's more a problem ain't it ?
|
|
Top
|
|
|
|
#3605 - 2000-07-25 02:30 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
Please tell me how !!!I'm not a Kix-crack like you !!! Would you be so kind to put me on my way with an example ?
|
|
Top
|
|
|
|
#3607 - 2000-07-25 04:12 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
Ok, ok,....but you have done more with Kix than I do !!! Thanx in advance !
|
|
Top
|
|
|
|
#3608 - 2000-07-25 04:57 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
BREAK ON;be sure to start the script in the root-directory wheer your sub-directories start $dir1="\directory1" $dir2="\directory2" ;etc.. SHELL '%comspec% /c dir /b $dir1 >> dir1.txt' SHELL '%comspec% /c dir /b $dir2 >> dir2.txt' OPEN (6,"dir1.txt") $currentfile=READLINE(6) DO WHILE ($currentfile<>"") $monthover=0 $date_old=getfiletime("$currentfile") $year_old=VAL(substr($date_old,1,4)) $month_old=VAL(substr($date_old,6,2)) $day_old=VAL(substr($date_old,9,2)) IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old<12) $monthover=1 GOTO decided ENDIF IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old=12) AND (@monthno>1) $monthover=1 GOTO decided ENDIF IF ((@monthno-$month_old)>1) $monthover=1 GOTO decided ENDIF IF ((@monthno-$month_old)=1) $monthover=1 GOTO decided ENDIF GOTO endloop :decided DEL "\$dir1\$currentfile" :endloop $currentfile=READLINE(6) LOOP CLOSE (6) OPEN (7,"dir2.txt") ;etc.. I haven't any more time on my hands (my boss seems to think that my time is hers) - but preferrably: create an array for the directories so it'll be easier to add new ones in the future.. (also, it's an ugly loop at the moment but hasty scripting makes for crappy scripts - sorry) I'll see if I can get around to writing a better one tomorrow.. Or if you want, e-mail me the directory-structure and I'll see if I can make it work for you. Fzz.
|
|
Top
|
|
|
|
#3609 - 2000-07-25 05:45 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
I hate posting so much on one subject but:The script has a subroutine "delroutine" because Kix doesn't support loop's withing loops... It will end with the error "Loop without while" - try to find that in a hurry! Anyone even trip over that one yet? hehe.. run the script from the root of your dir-structure:
BREAK ON DIM $dirarray[4] ;sorry for the similarity to the word diarriah *grin* $dirarray[0]="\directory" $dirarray[1]="\directory1" $dirarray[2]="\directory2" $dirarray[3]="\directory3" $countermax=4 ;(total array + 1) $counter=0 WHILE $counter<$countermax SHELL '%comspec% /c dir /b $dirarray[$counter] >> $dirarray[$counter].txt' $counter=$counter+1 LOOP $counter=0 WHILE $counter<$countermax GOSUB delroutine $counter=$counter+1 LOOP ;------------------------DELROUTINE--------------------- :delroutine OPEN (6,"$dirarray[$counter].txt")
$currentfile=READLINE(6) WHILE ($currentfile<>"") $monthover=0 $date_old=getfiletime("$currentfile") $year_old=VAL(substr($date_old,1,4)) $month_old=VAL(substr($date_old,6,2)) $day_old=VAL(substr($date_old,9,2)) IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old<12) $monthover=1 GOTO decided ENDIF IF (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old=12) AND (@monthno>1) $monthover=1 GOTO decided ENDIF IF ((@monthno-$month_old)>1) $monthover=1 GOTO decided ENDIF IF ((@monthno-$month_old)=1) $monthover=1 GOTO decided ENDIF ;see comment below GOTO endloop :decided DEL "\$dirarray[$counter]\$currentfile" :endloop $currentfile=READLINE(6) LOOP CLOSE (6) DEL "$dirarray[$counter].txt" ;delete the directory-content-file when done. RETURN ;------------------------------------------------------------- It looks like the script will delete all files of the previous month as soon as a new month is reached, but if you schedule the script to run evey 28'th day of the month it would only delete files created the month before.
|
|
Top
|
|
|
|
#3610 - 2000-07-25 06:01 PM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
And now I have to post AGAIN due to lack of perfectionism...Make the following correction: (replace line) $date_old=getfiletime("$dirarray[$counter]\$currentfile")
|
|
Top
|
|
|
|
#3613 - 2000-07-25 06:18 PM
Re: Date check then delete
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I haven't tested this yet.....I just took Fuentez's code and wrapped it in a loop for the subdirectories. code:
$root = "u:\" $tempfile = "temp.dat" shell "%comspec% /c dir $root /s/b > $tempfile"$q = open(1,"$tempfile",2) $file = readline(1) do $monthover=0 $date_old=getfiletime("$file") $year_old=VAL(substr($date_old,1,4)) $month_old=VAL(substr($date_old,6,2)) $day_old=VAL(substr($date_old,9,2)) Select case (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old<12) $monthover=1 gosub decided Case (VAL(substr(@date,1,4))-$year_old)>0 AND ($month_old=12) AND (@monthno>1) $monthover=1 gosub decided case ((@monthno-$month_old)>1) $monthover=1 gosub decided case ((@monthno-$month_old)=1) $monthover=1 gosub decided endselect $file = readline(1) While @error <> 0 $q = close(1) del $tempfile EXIT :decided ; "Commands to delete the file here" return
Bryce
|
|
Top
|
|
|
|
#3614 - 2000-07-26 09:16 AM
Re: Date check then delete
|
Anonymous
Anonymous
Unregistered
|
JPols >> crack in the head maybe.. *grin*
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 484 anonymous users online.
|
|
|