Jump to content

Roland

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by Roland

  1. It seems dat zip.au3 doesn't work under de lastest version of Windows 10. Windows 10 has discontinued support for direct calls to internal zip functions embedded in Windows 10. I build a script to unzip certain files. They work fine in windows 8.1 but don't do anything in Windows 10.
  2. to wakillon Thanx for the adjustment. I didn't test it for No files. #include <file.au3> #include <array.au3> #include <date.au3> $_FileDeleteByAge = _FileDeleteByAge ( @TempDir, "~DF*.tmp", 24, 0 ) ConsoleWrite ( "-->-- @error : " & @error & @Crlf ) ConsoleWrite ( "-->-- Files Delete By Age : " & $_FileDeleteByAge & @Crlf ) ;====================================================================== ; _FileDeleteByAge ; Author Roland Raijmakers ; Date 28-2-2011 ; Change: Error Handler by Wakillon 1-3-2011 ; Parameters $Path : Path to files ; $FileMask : File mask for files to be deleted ; $Age : Minimum Age (in hours) before files are deleted ; $FileRetention : Number of Files to be kept ; Function Deletes files in $FileMask to be deleted. ; Intented to cleanup old log, bak and tmp files ; There are two triggers before a file is deleted, $Age (in hours) and $FileRetention ; If both are met then a file is deleted. ; Return Values: ; @Error -1 No files found ; 0 or greater number Non-Deleted files ; Return No of deleted Files Func _FileDeleteByAge ( $Path, $FileMask="*.*", $Age=14, $FileRetention=0 ) Local $t[10], $Files2[1][4] Local $Date, $FileCount, $_FileTotDelete=0, $_NotDeleted=0 $Now = _NowCalc() $Files = _FileListToArray($Path, $FileMask, 1) If Not @error Then $FileCount = ubound($Files)-1 Redim $Files2[$FileCount+1][4] $Files2[0][0]=$FileCount For $i = 1 To $FileCount $t = FileGetTime($Path & "\" & $Files[$i], 0, 0) $Date = StringFormat("%02i/%02i/%02i %02i:%02i:%02i", $t[0], $t[1], $t[2], $t[3], $t[4], $t[5]) $Files2[$i][0] = $Files[$i] $Files2[$i][1] = $Date $Files2[$i][2] = _DateDiff('H', $Date, $Now) Next _Arraysort($Files2,1,1,0,1) ;Sort Array Ascending on column 1 with row 0 For $i = 1 To $FileCount If $i > $FileRetention And $Files2[$i][2] > $Age Then $_FileTotDelete += 1 $Files2[$i][3] = "DELETE" $_FileDelete = FileDelete($Path & "\" & $Files2[$i][0]) If Not $_FileDelete Then $_NotDeleted += 1 Endif Next SetError ( $_NotDeleted ) Return $_FileTotDelete - $_NotDeleted Endif SetError ( -1 ) EndFunc ;==> _FileDeleteByAge ( )
  3. As an system administrator I have a lot of log, bak and tmp files. In most situations I want to clean up the oldest files, but retaining te last log files. So I made a script wich looks at the age and number of files to be retained. Example: #include <file.au3> #include <array.au3> #include <date.au3> Delete al files in TempDir with mask ~DF*.TMP minimum 24 hours old, but keeping 7 versions _FileDeleteByAge(@TempDir, "~DF*.TMP", 24, 7) UDF: ;====================================================================== ; _FileDeleteByAge ; Author Roland Raijmakers ; Date 28-2-2011 ; Parameters $Path : Path to files ; $FileMask : File mask for files to be deleted ; $Age : Minimum Age (in hours) before files are deleted ; $FileRetention : Number of Files to be kept ; Function Deletes files in $FileMask to be deleted. ; Intented to cleanup old log, bak and tmp files ; There are two triggers before a file is deleted, $Age (in hours) and $FileRetention ; If both are met then a file is deleted. Func _FileDeleteByAge($Path, $FileMask = "*.*", $Age = 14, $FileRetention = 0) Dim $t[10] Local $Date Local $Files Local $Files2[1][4] Local $FileCount Local $Now $Now = _NowCalc() $Files = _FileListToArray($Path, $FileMask, 1) If $Files[0] > 0 Then $FileCount = ubound($Files)-1 Redim $Files2[$FileCount+1][4] $Files2[0][0]=$FileCount for $i = 1 to $FileCount $t = FileGetTime($Path & "\" & $Files[$i], 0, 0) $Date = StringFormat("%02i/%02i/%02i %02i:%02i:%02i", $t[0], $t[1], $t[2], $t[3], $t[4], $t[5]) $Files2[$i][0] = $Files[$i] $Files2[$i][1] = $Date $Files2[$i][2] = _DateDiff('H', $Date, $Now) Next _Arraysort($Files2,1,1,0,1) ;Sort Array Ascending on column 1 with row 0 For $i = 1 to $FileCount If $i > $FileRetention And $Files2[$i][2] > $Age Then $Files2[$i][3] = "DELETE" FileDelete($Path & "\" & $Files2[$i][0]) Endif Next ; _ArrayDisplay($Files2) ; Display Error for Testing Purposes Endif EndFunc ;==>_FileDeleteByAge
×
×
  • Create New...