Moderators Melba23 Posted July 14, 2012 Moderators Posted July 14, 2012 bgruett,The error means that the script could not get the date from the file - hence there is not an array to access. The obvious question is: How are you defining the $sRoot path variable? Are you adding a trailing backslash? If not, then the path you create with:$aDate = FileGetTime($sRoot & $aList[$i], 0, 0)will be missing a "" and so the command fail - which is what I imagine to be happening.Solutions would be:- 1. Add a trailing backslash to the $sRoot variable- 2. Add the backslash when you create the path:$aDate = FileGetTime($sRoot & "" & $aList[$i], 0, 0)Personally, I would always check the initial assignment of the $sRoot variable and add a backslash if required: If StringRight($sRoot, 1) <> "" Then $sRoot &= "" EndIfThen you need not worry about it from then on. Any use? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
bgruett Posted July 18, 2012 Posted July 18, 2012 (edited) Heh heh...that trailing backslash was missing, yes. And by putting it in, I'm no longer getting the error in question. Still not through the woods yet. Looks like the properly-formatted dates aren't so properly formatted after being processed by the script. When the array is cast, I get rows 0-5 in the following order: [YEAR][MONTH][DAY OF MONTH][HOUR IN 24-HOUR FORMAT][MINUTES][sECONDS]. However, the formatted date dispays as follows: [MINUTES]/[MONTH]/[DAY OF MONTH]. Essentially it looks like the [YEAR] field is being replaced in the formatting by the [MINUTES] field instead. I'm going to try and figure this last part out myself, since you guys have been so helpful. Thanks again! -Bob Edited July 18, 2012 by bgruett
bgruett Posted July 18, 2012 Posted July 18, 2012 Okay, so really dumb error on my part, and really simple solution. The issue was that I was loading the wrong field from the array into the formatted date variable. Pretty obvious, and makes perfect sense in retrospect, but since I'm still learning arrays it wasn't clear up front. Anyway, the current script (modified and ripped from various sources on these boards...and tested working in my environment) follows: #include <Array.au3> #include <File.au3> #include <Date.au3> ; put the root in a variable $sRoot = "C:Test" ; Retrieve a list of all the folders in $sRoot, and store that list as an array in $aList Global $aList = _FileListToArray($sRoot, "*", 2) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList ; You can delete the below line after seeing the output for the first time ;_ArrayDisplay($aList) ; This is a loop that runs from 1 to the number of items listed in the first element of the returned array For $i = 1 To $aList[0] ; For each folder, get the modified date/time and store its individual parts in array $aDate $aDate = FileGetTime($sRoot & $aList[$i], 0, 0) ; FileGetTime("filename" [, option [, format]]) ; Look at what FileGetTime() puts into $aDate ; You can delete the below line after seeing the output for the first time ;_ArrayDisplay($aDate) ; Build the properly formatted date string for _DateDiff()'s needs $sDate = $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2] ;0 index stores the year, 1 index stores month, 2 index stores day ; Look at what we made into $sDate ; You can delete the below line after seeing the output for the first time ;msgbox(0,"Check Output", $sDate) ; Use _DateDiff() to see if the difference is greater than 3 days, and if it's true, then delete the folder and all its subfolders If _DateDiff("D", $sDate, _NowCalcDate()) > 3 Then DirRemove($sRoot & $aList[$i], 1) Next Obviously I take zero credit for this. Which is probably why it works so beautifully! Thanks, Bob
DavidLago Posted July 19, 2012 Posted July 19, 2012 I got a script that does that with files, with an option to switch to folders. Check it out:
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