Page 1 of 2 12>
Topic Options
#3595 - 2000-07-25 11:17 AM Date check then delete
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
#3596 - 2000-07-25 11:53 AM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jasper,

try a combination of 'GetFileTime()'
and the macros '@mdayno'&'@monthno'

You just have to strip out the corresponding
values out of the format 'YYYY/MM/DD HH:MM:SS'
that is returned by 'GetFileTime()' ; best to use is the 'SUBSTR()' function

any Questions???


Jochen

_________________________



Top
#3597 - 2000-07-26 12:18 AM Re: Date check then delete
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
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
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
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
#3601 - 2000-07-25 02:11 PM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jasper,
are the filez reside in one folder ????
this should keep the script as short as a idontknowwhat!!!
_________________________



Top
#3602 - 2000-07-25 02:17 PM Re: Date check then delete
Anonymous
Unregistered


Nope....
The files are also in subfolders !
That's more a problem ain't it ?


Top
#3603 - 2000-07-25 02:24 PM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
yep,
but it will only inflate your script a little bit !!!!!
_________________________



Top
#3604 - 2000-07-25 02:28 PM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
whhooops,

missed the reply of Fuentez ....!!!
after a quick 'EYE_BALL_FLEW_OVER' it seems
to me valuable for Your problem and working!!

good shot Gringo

Cheers Jochen

_________________________



Top
#3605 - 2000-07-25 02:30 PM Re: Date check then delete
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
#3606 - 2000-07-25 03:49 PM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Not so fast Yakamoto,
i am not a kix crack!
see issue : http://kixtart.org/board/Forum1/HTML/001050.html

but ok i'll give it a try !

_________________________



Top
#3607 - 2000-07-25 04:12 PM Re: Date check then delete
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
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
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
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
#3611 - 2000-07-25 06:07 PM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jasper,

copy the last reply of Fuentez to an empty
notepad file , save it as 'whatever.kix'
(make sure that the layout makes sense)
replace the values of $dir1 = "\..." with an existing file structure on Your Computer ...
best is to make a small test environment...
call the Kix - script with a batch from the same dir , sample of whatever.cmd`:

code:

@echo off
Kix32.exe %0\..\whatever.kix
REM assumes that kix32.exe is in the path [system32]
pause
REM to see the results
EXIT

and play some test rounds ....
to see what happens with every single step
call the script with
Kix32.exe %0\..\whatever.kix /d
what starts the script execution in debug mode [you have to hit return for each line]

hope this will get you on the path!!!

Jochen

_________________________



Top
#3612 - 2000-07-25 06:11 PM Re: Date check then delete
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Fuentez,

the only crack to be involved here , seems to be You

Jochen

_________________________



Top
#3613 - 2000-07-25 06:18 PM Re: Date check then delete
Bryce Offline
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
Unregistered


JPols >> crack in the head maybe.. *grin*
Top
Page 1 of 2 12>


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

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.064 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

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