Jump to content

Another 'How To Delete Folders By Age' Question


Recommended Posts

I know this question has been asked, and has even been answered ( for example), but even after reading through the AutoIT commands and trying to reverse engineer the fantastic script Varian put together, I'm still having trouble, and I was hoping for some help.

Basically, I have a script that runs once an hour, every hour, duplicating a folder into a backup location and stamping it with a date and time stamp. I'm using the simple DirCopy command with some rudimentary macros.

An example of what I'm talking about follows:

DirCopy("[SOURCE DIR]", "[TARGET DIR]\[" & @MON & "-" & @MDAY & "-" & @YEAR & "]-[" & @HOUR & @MIN & " Hours]", 1)

Obviously I've replaced the source and target directories in the above example.

When run, the source folder is copied to a \Backups\ alternate folder, as shown in the following examples:

- ...\Backups\[07-06-2012]-[0000 Hours]

- ...\Backups\[07-06-2012]-[0100 Hours]

- ...\Backups\[07-06-2012]-[0200 Hours]

- ...\Backups\[07-06-2012]-[0300 Hours]

- ...\Backups\[07-06-2012]-[0400 Hours]

This goes on for a 24 hour cycle, reaching 2400 hours, at which point the date rolls over and the whole process starts again.

The obvious problem is that I don't want these backup folders filling up the entire drive. Therefore, I'd like to add functionality to the script to purge any backup folders previously created which are more than a few days old.

Again, I've reviewed the commands in the linked article, and I've done my best to reverse engineer the linked script, but I just can't get it to work. My goal isn't to have an interactive script, but rather to have a script that will run unattended on its own without user intervention. If the script is attended, I might as well just go in and manually purge the old files.

I hate to ask someone else to do my work for me, but I'm at the end of my rope with this particular issue. If anyone can (and is willing) to help, I'd really appreciate it.

Thanks,

Bob

Link to comment
Share on other sites

Varian's script looks 'feature complete' for what you want with a couple of tweaks here and there. My suggestion read the Help file and post some code if you get stuck. Good luck.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

use file find, use attrib to check for directory, then in the loop something like the following to use for your comparisons.

#include<array.au3>
$sFile='Backups[07-06-2012]-[0000 Hours]'
$aDate=StringRegExp($sFile,'(?:.*)(?:[)([0-9]{2})(?:-)([0-9]{2})-([0-9]{4})]-[([0-9]{4})(?: Hours])',3)
_arraydisplay($aDate)
Edited by DicatoroftheUSA
Link to comment
Share on other sites

The major difference between the scripts you're looking at and what you want to do is that the other scripts delete files/directorires based upon one of the system file dates, you want to use a portion of the directory name itself to determine which to delete. If it's not too late, you'd find life easier if you named your files using a YYYY-MM-DD format instead of MM-DD-YYYY. Then your directory names would sort in chronological order and you could use a simple greater-than string compare to choose which ones to delete.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...