Sign in to follow this  
Followers 0
ksmith247

Using data from an array

5 posts in this topic

I seem to be a bit over my head in this one. Thanks to weaponx, I now have a list of file paths/names in an array. I need to open each file (they're plain text) and search for a particular text string. If I find the string, I will probably throw the file out. If I DON'T find the string, I will write the computer name to another file someplace.

My question is how do I get each element out of this array? Do I write the array to a file then read the file line by line? Surely not. I have been looking for a way to read the first element (each element is a path to a file), open the file, parse through then move on to the next element. Obviously I am not sure what to look for in the help file.

Can someone please point me in the right direction? -Thanks.


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is easy stuff.

For $X = 0 to Ubound($array)-1
 If StringInStr(FileRead($array[$X]),"SEARCH STRING") Then
 FileDelete($array[$X])
 Else
 EndIf
 Next
Edited by weaponx

Share this post


Link to post
Share on other sites

Look at the array information in the helpfile

$array[0] gets the first element, $array[1] the second, etc. It is usually a good Idea to have $arrray[0] contain the number of other entries so you know how many times to loop through.


Regards,Josh

Share this post


Link to post
Share on other sites

Something like this:

Global $MyArray[4] = [0, 10, 20, 30]
$MyArray[0] = UBound($MyArray) - 1

For $i = 1 to $MyArray[0]
    ConsoleWrite($MyArray[$i] & @CRLF)
Next

There is probably a better way of doing it though.

Share this post


Link to post
Share on other sites

This is my first shot at doing something other than ArrayDisplay. Never heard of Ubound before. As usual, it works just fine weaponx. Thanks.


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0