July 3, 2012 at 4:53 am
Hi,
You'll need to download AutoIT to use this. With it you can alter and compile this script to an executable. http://www.autoitscript.com/site/autoit/
Obviously you'll need to tweak this script for your own needs.
Paste into AutoIT and save as .au3. That way you'll be able to use the fantastic help. (Select keyword, press F1)
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Delete files older than 30 days that is NOT the 1st of the month.
#include <file.au3>
#include <date.au3>
#include <Array.au3>
Global $LocalFolderSrc = "" ;The place where your databases are backed up to
Global $LocalFolderDest = "" ;The local folder where you want to have your backups stored
Global $NetworkFolderDest = "" ;The network share where you want to copy to
;Copy the files
FileCopy($LocalFolderSrc,$LocalFolderDest)
FileCopy($LocalFolderSrc,$NetworkFolderDest)
;Clean up certain aged files
Cleanup($LocalFolderDest)
Cleanup($NetworkFolderDest)
;Clean up original backup location
FileDelete($LocalFolderSrc)
Func Cleanup ($FolderLoc = "")
If Not FileExists($Folder) Then
MsgBox(0,"Folder does not exist.",$Folder,5)
Return "Error"
EndIf
;FileGetSize
Global $DateLimit = _DateAdd('M',-1,_NowCalc())
Global $FileName, $FileList, $i, $FileDate, $Mon, $Year
;When subtracting 1 from @Mon the leading 0 is dropped.
;This makes the value much lower when comparing dates
IF @MON > 1 Then
$Mon = @Mon - 1
$Year = @YEAR
If StringLen($Mon) = 1 Then
$Mon = "0" & $Mon
EndIf
Else
$Mon = "12"
$Year = @YEAR - 1
EndIf
$DateLimit = $Year & $Mon & @MDAY & @HOUR & @min-2 & @sec
;Get a list of all files in the specified folder
$FileList = _FileListToArray($Folder)
Global $DeleteCount = 0
If $FileList[0] > 0 Then
;Loop through all the files
for $i = 1 to $FileList[0]
Local $FullPath = $Folder & "\" & $FileList[$i]
;Local $Ans
;Asume it's a folder if it doesn't contain _bak.rar in the name
if StringInStr($FullPath, "_bak.rar") > 0 Then
;Get the creation date of the file
$FileDate = FileGetTime($FullPath,1,1)
;Ignore the first day of the month
if StringMid($FileDate,7,2) <> "01" Then
;Check if the file is too old
if $FileDate < $DateLimit Then
FileDelete($FullPath)
$DeleteCount = $DeleteCount + 1
EndIf
EndIf
EndIf
Next
EndIf
Local $Title = 'Files sucessfully deleted.'
Local $Ans = $DeleteCount & " files deleted from " & $FolderLoc & @CRLF & @CRLF & "Criteria : Older then a month and not the 1st of a month."
MsgBox(0,$Title,$Ans,25)
EndFunc
Exit
Hope this helps.
Viewing post 16 (of 15 total)
You must be logged in to reply to this topic. Login to reply