NoobieAutoitUser Posted September 7, 2017 Share Posted September 7, 2017 (edited) Hi folks, I am moving away from Windows 'batch' to Autoit. A lot more power with Autoit, and flexibility. Also a lot more to learn I wrote a script that automatically backups something. It makes a back up every time I launch the script. It then deletes all backups except three. That is the problem. Everything works great till the deletion part. If there are files to delete, it works great. If there are not files to delete I get this error 'Array variable has incorrect number of subscripts or subscript dimension range exceeded'. I'm fairly sure that is has something to do with the 'Ubound' part. From what I read, do I need to resize the array? Or how do I move past the error. I am new to this, and not sure how do error checking. Thanks for any input. expandcollapse popup#include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> Dim $szDrive, $szDir, $szFName, $szExt $openfile = 'D:\Z-Users\Last-Time\AppData\Roaming\Something\Saves' $foldertoworkin = 'G:\Temp_D1\' $filename = _PathSplit($openfile, $szDrive, $szDir, $szFName, $szExt) _ArrayDisplay ($filename,"") $Filenamevalue = _ArrayToString($filename,'',3,3) ; MsgBox(0, "Test", $szFName) FileChangeDir($openfile) Local $param01 = "C:\Program Files\7-Zip\7z.exe" Local $param02 = " a -mx1 -r " Local $param03 = $foldertoworkin ; Local $param04 = $szFName Local $param04 = 'Something--' Local $param05 = ".zip" ;Create zip Local $sRun = $param01&$param02&$param03&$param04 &"-"& @MON &"-"& @MDAY &"-"& @YEAR &"_"& @HOUR &"-"& @MIN &"-"& @SEC&$param05 ConsoleWrite(' $sRun >'&$sRun&'<'&@CRLF) ; ..this way you can see what is gonna execute RunWait($sRun, "", @SW_HIDE) ;############################################################################################## Local $sFilePath = $foldertoworkin Local $aFilePath = _FileListToArrayRec($sFilePath, "*", 1,0,0,2) Local $aFileTime[1][2] ;============================================================================= _ArrayColInsert($aFilePath, 1) ; insert a second column For $i = 1 To $aFilePath[0][0] ; now it's [0][0] - row index 0, column index 0 $aFilePath[$i][1] = FileGetTime($aFilePath[$i][0], 1, 1) ; in column 1 (remember 0-indexed - if you start counting by one it's your second) Next ;============================================================================= _ArrayDelete($aFilePath, 0) ; delete number of indexes - there is no filepath inside _ArraySort ($aFilePath,1, 0, 0, 1) ;sort by date _ArrayDisplay($aFilePath) ;============================================================================= For $m = 3 To UBound($aFilePath, 1) ; '3 to ubound' takes the first '3' off the top of the list returned form array (make sure what you want is on the top) ;ConsoleWrite("FileDelete: " & $aFilePath[$m][0] & @CRLF) ; instead of real deletion only saying what will be deleted - just for my security ;if _FileInUse($myfile[$n], 0) And MsgBox(0,"",@error) then continueloop; ADDED ;if $aFilePath[$m][0] And MsgBox(0,"",@error) then continueloop; ADDED FileDelete($aFilePath[$m][0]) ;if FileDelete($aFilePath[$m][0]) And @error = 1 then continueloop; ADDED Next ;############################################################################## ProcessSetPriority("Something.exe", 3) Edited September 8, 2017 by NoobieAutoitUser All references to a game have been removed Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 7, 2017 Moderators Share Posted September 7, 2017 NoobieAutoitUser, Asking for help with scripts that launch games usually means an instant thread lock, however, as the question you are asking is not directly related to the game itself, I am prepared to leave this one open. However, in return I expect you to read the Forum rules carefully before you post again and in future do not make such mistakes again. 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 Link to comment Share on other sites More sharing options...
NoobieAutoitUser Posted September 7, 2017 Author Share Posted September 7, 2017 @ Melba23 - I understand, and I had seen that about games, and I was thinking this was legit. I know better now, thanks for the 'heads up' Link to comment Share on other sites More sharing options...
Skysnake Posted September 12, 2017 Share Posted September 12, 2017 ; Try this? local $currentarchives = UBound($aFilePath, 1) ; '3 to ubound' takes the first '3' off the top of the list returned form array (make sure what you want is on the top) If $currentarchives > 3 Then ; --- wrap the loop in an If Test For $m = 3 To $currentarchives Step 1 ; now loop ;ConsoleWrite("FileDelete: " & $aFilePath[$m][0] & @CRLF) ; instead of real deletion only saying what will be deleted - just for my security ;if _FileInUse($myfile[$n], 0) And MsgBox(0,"",@error) then continueloop; ADDED ;if $aFilePath[$m][0] And MsgBox(0,"",@error) then continueloop; ADDED FileDelete($aFilePath[$m][0]) ;if FileDelete($aFilePath[$m][0]) And @error = 1 then continueloop; ADDED Next EndIf ; --- wrap the loop in a n If Test Skysnake Skysnake Why is the snake in the sky? 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