jazzyjeff Posted November 24, 2010 Share Posted November 24, 2010 I have read through the wiki on Array's and it all makes sense up until "Changing Array sizes with ReDim". Need to go over it a few more times for that to sink in. What I didn't see covered in the wiki was what if you don't know the elements to store in an array. The examples always told you the data in the array i.e. "Element 1|Element 2|Element 3". I have a folder than contains numerous user folders e.g. Users ----->>CameronDiaz ----->>GeorgeClooney ----->>TomCruise There are too many folders in the Users directory for me to add these as data elements in an array. I found the function "_FileListToArray", which I believe will find the data I need. So I have this code that I basically want to use to cycle through a directory and reset permissions. I have setup the script below, so I can see what folders it finds, but it never returns any folders. #include<file.au3> #include<array.au3> $staffDir = _FileListToArray("\\server\users$\test\","*",2) For $i = 1 To $staffDir[0] $staffDir = $staffDir & $i MsgBox(0,"Users","This user folder is in the array: " & $staffDir) Next I know I have messed up in the For loop somewhere, but I can't figure this out. I had help from someone in the forums before and promised I would learn this, so not to bother anyone here. :-) I am trying! Any helps appreciated. Thanks, Jeff Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 24, 2010 Moderators Share Posted November 24, 2010 jazzyjeff,The problem is this line:$staffDir = $staffDir & $iYou use the $i in the For statement as the index value to loop through the array. Your line above actually clears the array - which is why you get no results! Change your loop to read:For $i = 1 To $staffDir[0] MsgBox(0,"Users","This user folder is in the array: " & $staffDir[$i]) Nextand you should find your folders. 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...
jazzyjeff Posted November 24, 2010 Author Share Posted November 24, 2010 I am plugging away at this. I now have this script: #include<file.au3> #include<array.au3> $staffDir = _FileListToArray("\\server\users$\test\","*",2) $user ="" For $i In $staffDir $user = $user & $i MsgBox(0,"Users","This user folder is in the array: " & $user) Next It brings up the folder names, although a little oddly. Each message box is populating with the previous folder name from the array... I'll keep plugging away, but please let me know if there is a better way of doing this. Thanks, Jeff Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 24, 2010 Moderators Share Posted November 24, 2010 JazzyJeff,For $i In $staffDir If Not IsNumber($i) Then MsgBox(0,"Users","This user folder is in the array: " & $i) NextYou need the If to miss out the count in the first element. But I would go with the code I posted above. 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...
hannes08 Posted November 24, 2010 Share Posted November 24, 2010 (edited) Hey jazzyjeff, If you want to do it using with "For ... In" Try something like this: #include<file.au3> #include<array.au3> $staffDir = _FileListToArray("\\server\users$\test\","*",2) $user ="" For $i In $staffDir MsgBox(0,"Users","This user folder is in the array: " & $i) Next Well, Melba32 is right though... Regards, Hannes Edited November 24, 2010 by Hannes123 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
jazzyjeff Posted November 24, 2010 Author Share Posted November 24, 2010 Thank you both for your responses. I tried Melba's solution before heading to lunch and this worked for me. Sorry I didn't reply sooner. 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