Jesthe11 Posted May 28, 2016 Share Posted May 28, 2016 So here is the code, I am trying to make it so I can use the array of filegettime to check each folders (directories) creation date in a directory and then delete if they are outside a specified date and time When I try to use date[1] in my msgbox it tells me it the subscript is inaccessible $localFolders = _FileListToArray(@ScriptDir & "\Local", "*", 2) For $localFolder In $localFolders $size = DirGetSize(@ScriptDir & "Local\" & $localFolder) $date = FileGetTime(@ScriptDir & "Local\" & $localFolder,1,0) MsgBox(0,'',$date[1] & @CRLF & $localFolder & @CRLF & Round($size / 1000000,3) & " MB") Next Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 29, 2016 Moderators Share Posted May 29, 2016 Jesthe11, I t looks as if you are missing a "\" in the path you pass to DirGetSize and FileGetTime: @ScriptDir & "Local\" & $localFolder should read: @ScriptDir & "\Local\" & $localFolder) You should always check the @error return value from functions which take a path - in this case I suspect they would both have shown the problem. 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...
EmilyLove Posted May 29, 2016 Share Posted May 29, 2016 To add to m23's post, most if not all macros involving directories never have a "/" and thus need to always be added. I have no idea why tho. Link to comment Share on other sites More sharing options...
RTFC Posted May 29, 2016 Share Posted May 29, 2016 (edited) 20 hours ago, BetaLeaf said: I have no idea why tho. Because (for historical reasons) directory names are just file names with the <directory attribute> set. And filenames cannot contain slash/backslash characters because they are used to indicate directory tree nesting. Edited May 30, 2016 by RTFC EmilyLove 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Jesthe11 Posted May 29, 2016 Author Share Posted May 29, 2016 Even with adding the black slash I am getting the same, ERROR: Subscript used on non accessible variable, but for some reason, even without the black slash before the input in DirGetSize it was working..... and I did notice that my filegetime was using the string as an output and not the array, yet that still did not fix the issue when I changed it $localFolders = _FileListToArray(@ScriptDir & "\Local", "*", 2) For $localFolder In $localFolders $size = DirGetSize(@ScriptDir & "\Local\" & $localFolder) $date = FileGetTime(@ScriptDir & "\Local\" & $localFolder,1,0) MsgBox(0,'',$date[1] & @CRLF & $localFolder & @CRLF & Round($size / 1000000,3) & " MB") Next Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 29, 2016 Moderators Share Posted May 29, 2016 Jesthe11, I have it - you need to change the syntax for looping through the array. _FileListToArray returns the count in the [0] element - which is taken to be a valid return when using the For...In...Next looping syntax, which in my opinion should only ever be used for object collections. Thus the path is not valid and the function calls fail - I did say you should check the return values..... When you use an array you should always use the For...To...Next syntax like this: For $i = 1 To $localFolders[0] $size = DirGetSize(@ScriptDir & "\Local\" & $localFolders[$i]) $date = FileGetTime(@ScriptDir & "\Local\" & $localFolders[$i], 1, 0) MsgBox(0, '', $date[1] & @CRLF & $localFolder & @CRLF & Round($size / 1000000, 3) & " MB") Next Now you only try to use the valid paths within the array. By the way, you do realise that you can ask _FileListToArray to return the full path? Just set the $bReturnPath parameter and then you will not need to add the paths within the loop. 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...
Jesthe11 Posted May 29, 2016 Author Share Posted May 29, 2016 Awesome it is working now! Thank you 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