Sign in to follow this  
Followers 0
bgruett

Another 'How To Delete Folders By Age' Question

5 posts in this topic

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

Share this post


Link to post
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.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • Mag91
      By Mag91
      Hey Everybody,
      as you know im on a very low autoit-level.
      My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.
       
      The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
      There can be 1 PDF or even 15 PDFs.
      i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language
       
      THANKS!
       
    • kawliga751
      By kawliga751
      I have established how to get tomorrows date however I can't seem to figure out how to format the date into my required format of MM/DD/YYYY.  
      I have this:
      $today=_DateToDayValue(@YEAR,@MON,@MDAY) Dim $Y, $M, $D $tomorrow=_DayValueToDate($today+1, $Y, $M, $D) The _DateToDayValue seems to have a fixed format.  I've also tried a :
      $vardate = _DateAdd( 'd',1, _NowCalcDate()) with a "StringSplit" and/or StringFormat but the _NowCalcDate seems to also be fixed to a YYYY/MM/DD format.
      I'm sure I'm missing something simple but am at a loss.
      Any help would be MUCH appreciated
       
       
    • TheAutomator
      By TheAutomator
      How can you get the downloads folder in AutoIT?
      As far as i know there isn't a macro for it right? like @Downloads or something?
      The ugly solution would be typing in the whole path but what if the user has chosen another location?
      Need to clear that folder regularly on my work and on different accounts..
      regards, TheAutomator
    • ur
      By ur
      We can get a list of file using the below code.
      Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.??
      And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?