Chaguito
(Getting the hang of it)
2004-03-04 08:18 PM
Help with folder cleanup

Hello all...I looked into the cleandirectory() udf and doesn't work for what I need.

The thing is that there are folders created daily and after a certain amount of days need to be removed. If I use cleandirectory() it will do it but will also delete files from the folders that need to be kept.

This is a sample directory structure:

folder_03mar2004
folder_02mar2004
.
.
.
folder_26feb2004


How can I delete the folder named folder_26feb2004 without deleting files from the other folders????

Thanks
Thanks


LonkeroAdministrator
(KiX Master Guru)
2004-03-04 08:23 PM
Re: Help with folder cleanup

asking for clarification...
so, you don't want to delete by folder or file date but the date specified in the folder name?


Chaguito
(Getting the hang of it)
2004-03-04 08:35 PM
Re: Help with folder cleanup

Quote:

asking for clarification...
so, you don't want to delete by folder or file date but the date specified in the folder name?




That is the plan!!!


Co
(MM club member)
2004-03-04 09:47 PM
Re: Help with folder cleanup

You have to make a script which looks to todays date and the creation date of the folders. Lets say you want to delete every folder older than one week.

There are some time UDF's. Search for it in the UDF forum...


Chaguito
(Getting the hang of it)
2004-03-04 09:53 PM
Re: Help with folder cleanup

And it is the cleandirectory() udf but it does not work for me because I could have certain files on all folders with dates older and would be deleted.

Anyways I'll do some more searching but the help is very appreciated!!!!


Co
(MM club member)
2004-03-04 09:59 PM
Re: Help with folder cleanup

Quote:

And it is the cleandirectory() udf but it does not work for me because I could have certain files on all folders with dates older and would be deleted.





No, it is not...

I meant DateTimeDiff(), DateCalc(), DateTimeMath(),DateMath(), SerialDate(), etc


Co
(MM club member)
2004-03-04 10:07 PM
Re: Help with folder cleanup

And... You don't have to delete files and subdirectories only the folders on top like 26_februari, 27_februari, etc

Kdyer
(KiX Supporter)
2004-03-04 10:22 PM
Re: Help with folder cleanup

OK.. Here is something that I have been fumbling around with -

Requires the following UDFs:
WSHPIPE()
DATECALC()
LOGGER()
MAILER()

 CLS

BREAK ON
IF EXIST('H:\Profileremove.csv') DEL 'H:\Profileremove.csv' ENDIF
FOR EACH $i IN Split('01 03')
$loc='\\CITRIX'+$i+'\admin$$\profiles\'
$rc=WshPipe('%comspec% /c dir '+$loc+'*.*',1)
FOR EACH $line IN $rc
IF NOT instr($line, 'File Not Found')
;?$line
; -- Convert American Dates to European format
$dtchk=split(split($line)[0],'/')[2]+'/'+split(split($line)[0],'/')[0]+'/'+split(split($line)[0],'/')[1]
;?$dtchk
$name=split($line)[17]
$dt=DATECALC($dtchk,@date)
IF val($dt)>2 AND len($name)>3 AND $name<>'All Users' AND $name<>'DEFAULT'
?'Days ago: '+$dt
?$loc+$name
;SHELL '%COMSPEC% /C RD /S /Q '+chr(34)+$loc+'\'+$name+chr(34)
If @error<>$err=1 ELSE $err=0 ENDIF
$logdata='Days ago: '+$dt+','+$loc+$name+','+$err
LOGGER('H:\Profileremove.csv',$logdata+@crlf)
ENDIF
ENDIF
NEXT
NEXT
MAILER('recipient@@company.com','Profiles remove Log','Removal Log','H:\Profileremove.csv')


Thanks,

Kent