#144831 - 2005-08-05 04:27 PM
Count files and filesize, then remove files older then 1 day
|
Zakonski
Fresh Scripter
Registered: 2005-08-05
Posts: 5
|
I've read a post about deleting files which were older then 30 days. I've tried to edit the script, but it didn't work. Here's what I want: For example, it's the 5th of July 2005. There's a folder ..\TMP. I want to count the total of files which are older then the 5th of July 2005 I want to count the total size of files which are older then the 5th of July 2005 The result may be printed on the screen, or to a file. After that it needs to delete all the files, older then the 5th of July 2005.
Any suggestions? My skills with scripting are not that good, so type slowly please
|
Top
|
|
|
|
#144833 - 2005-08-05 11:03 PM
Re: Count files and filesize, then remove files older then 1 day
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
take a look at the UDF's DIRPlus() and FlipCTime() and TimeConvert().
ahh... waht the hell... silver platter time
Code:
Call 'g:\kix\udf\dirplus\DirPlus.kix' Call 'g:\kix\udf\FlipcTime\flipcTime.kix' Call 'g:\kix\udf\TimeConvert\TimeConvert.kix'
DIM $DeletedFiles[0]
;get and array of all file on the folder $files = Dirplus("c:\temp",'/a-d /s')
for each $file in $files ;the current date/time of the file $TS = split($file.datelastmodified)
;need to format the date/time into usable values
;this tunes the time in to Milltary time $ts[1] = timeconvert($ts[1]+$ts[2])
;this puts the date into a yyyy/mm/dd format $ts[0] = split($ts[0],'/') $ts[0] = $ts[0][2]+'/'+$ts[0][0]+'/'+$ts[0][1]
;the age of the file in seconds since 1970/1/1 $ts = flipctime($ts[0],$ts[1])
;the current number of seconds since 1970/1/1 $currentTime = flipctime(@DATE,@TIME)
;Check to the the number of seconds that have elapsed since the .lastdatemodified time on the file ;of longer than 24hours or 86400 seconds, the file is old enough. If $currentTime - $ts > 86400 ;add the wanted information to the $deletedFiles Array $deletedFiles[ubound($deletedFiles)] = $file ;resize the array by 1 redim preserve $deletedFiles[ubound($DeletedFiles)+1] EndIf next
If ubound($deletedFiles) > 0 ;need to trim down the size of the array by one. redim preserve $deletedFiles[ubound($deletedFiles)-1] Else ;no files were found that were older than 1 day $deletedFiles=0 EndIf
"Number of Files that are older than 1 day = " + (ubound($DeletedFiles)+1)
;add up the size of the files to be deleted for each $file in $DeletedFiles $deletedFileSize = $file.size+$deletedFileSize next
? "Total Size of files to be deleted = " $deletedFileSize
;time to delete the files, you will neede to uncomment this... ;because it WILL delete the files!! ;for each $file in $deletedFiles ; $file.delete ;next
|
Top
|
|
|
|
#144834 - 2005-08-06 02:19 PM
Re: Count files and filesize, then remove files older then 1 day
|
Zakonski
Fresh Scripter
Registered: 2005-08-05
Posts: 5
|
Thanks for helping Bryce, when the directory is empty, it says:
Number of files older then 1 day = 0 Total size of files to be deleted =
When I place some temp files in de TEMP dir, it says:
ERROR : array reference out of bounds! Script: C:\Documents and Settings\mzi\Bureaublad\KIX\testomgeving\monitorentempfiles.kix Line : 19
?
|
Top
|
|
|
|
#144841 - 2005-08-07 06:58 AM
Re: Count files and filesize, then remove files older then 1 day
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Quote:
Quote:
...Script: C:\Documents and Settings\mzi\Bureaublad\KIX\testomgeving\monitorentempfiles.kix Line : 19...
Zakonski also uses a Dutch OS...
AHH HA!
it seems that .datelastmodified returns the date/time in the format that is given by the OS.
a ? %file.datelastmodified returns "8/6/2005 11:37 pm" on my system m-d-yyyy
ok based off what you told me...
1. you dont need this line. delete or comment out. and you dont need the timeconvert() UDF Code:
$ts[1] = timeconvert($ts[1]+$ts[2])
2. need to change this Code:
$ts[0] = split($ts[0],'/') $ts[0] = $ts[0][2]+'/'+$ts[0][0]+'/'+$ts[0][1]
to
Code:
$ts[0] = split($ts[0],'-') $ts[0] = $ts[0][2]+'/'+$ts[0][1]+'/'+$ts[0][0]
Bryce
|
Top
|
|
|
|
#144846 - 2005-08-07 03:35 PM
Re: Count files and filesize, then remove files older then 1 day
|
Zakonski
Fresh Scripter
Registered: 2005-08-05
Posts: 5
|
Bryce, it works fantastic! Thank you very much!
|
Top
|
|
|
|
#144847 - 2005-08-07 09:17 PM
Re: Count files and filesize, then remove files older then 1 day
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Bryce,
When I add this to the mix I get bunch of errors
Code:
$SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On')
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|