jbennett Posted October 21, 2008 Share Posted October 21, 2008 Hi everyone, I'm currently trying to get my AutoIT code to delete all folders that are older than 4 weeks.My code initially creates a folder with the computer name and then creates a folder within this that is named as the current date.I'm trying to get the code below to delete any folders that are older than 4 weeks$oldfolders = "c:\backup\" & @computername & "\" & @mday & "-" & @mon & "-" & @year - 4if FileExists ($oldfolders) Then DirRemove ($oldfolders, 1)Anyone have any ideas, thanks Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 21, 2008 Share Posted October 21, 2008 #include <Array.au3> #include <Date.au3> #include <File.au3> ;Root folder $sourceFolder = @ScriptDir & '\' ;Gather files into an array $fileList = _FileListToArray($sourceFolder, "*", 2) Dim $found[1] ;Loop through array For $X = 1 To $fileList[0] ;Retrieve creation time of file $Date = FileGetTime($sourceFolder & "\" & $fileList[$X], 1, 0) ;Format date for use with Date UDF $fDate = StringFormat("%s/%s/%s %s:%s:%s", $Date[0], $Date[1], $Date[2], $Date[3], $Date[4], $Date[5]) ;Calculate age, remove files older than one week If _DateDiff('w', $fDate, _NowCalc()) > 4 Then ;FileDelete($sourceFolder & "\" & $fileList[$X]) _ArrayAdd($found, $sourceFolder & $fileList[$X]) ;MsgBox(1, "Files deleted:", $fileList[$X], 1) EndIf Next _ArrayDisplay($found) Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
jbennett Posted October 21, 2008 Author Share Posted October 21, 2008 (edited) Thanks. The only concern I have is that I seem to need to change the "4" to "0.5" to get it to recognize 1 week. Like the following:If _DateDiff('w', $fDate, _NowCalc()) > 0.5 ThenEDIT----If I change it to 'd' and >7 then this seems to work pretty well for my situation Edited October 21, 2008 by jbennett Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now