Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted

jazzyjeff,

The problem is this line:

$staffDir = $staffDir & $i

You 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])
Next

and you should find your folders. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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

  • Moderators
Posted

JazzyJeff,

For $i In $staffDir
    If Not IsNumber($i) Then MsgBox(0,"Users","This user folder is in the array: " & $i)
Next

You need the If to miss out the count in the first element. But I would go with the code I posted above. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (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... :graduated:

Regards,

Hannes

Edited by Hannes123
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...