Jump to content

Help in loops while file reading


Recommended Posts

Hey everybody!

I'm stucked in a script that works like this:

First, I copy a txt file to a path.

Then, I begin looking at the copied file for a key. I use _StringBetween function and when I find this key, I show this in a MsgBox.

But I don't want to repeat this key, if I find another key equals to the first, I ignore it.

My original txt file may change. So I want the script to keep copying this file (in a loop) and overwriting it so my copied txt file may keep looking at the copied file for a new key.

It will work like this:

Test.txt:

Begin key1 End

Begin key2 End

Begin key3 End

Then I copy this file to another path, but with the same name (I will call this new file as "TestCopied.txt")

TestCopied.txt:

Begin key1 End

Begin key2 End

Begin key3 End

Then I change something in my Test.txt file:

Begin key1 End

Begin key2 End

Begin key3 End

Begin key4 End (new key entered)

And then the script copy and overwrite to TestCopied.txt:

Begin key1 End

Begin key2 End

Begin key3 End

Begin key4 End

and my script keep looking at new keys. When it find the key4, it shows me a MsgBox.

Could you understand?

I already wrote a script but it doens't work the way I want...

It doesn't copy the file and do this loop to keep looking at keys at the copied file.

Hope someone can help me.

PS: the code is on attachments. It's not working and it's a lil confusing to understand...

Thanks!

scriptSA.txt

Link to comment
Share on other sites

Well, the only way to accomplish this is by employing arrays.

- Use _FileReadToArray to read your Test.txt file, then use it to read TestCopied.txt

- Merge the two arrays into one (_ArrayConcatenate)

- get the unique elements from the big array (_ArrayUnique)

- write the result array to TestCopied.txt (_FileWriteFromArray)

Job done :unsure:

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • 2 weeks later...

Well, the only way to accomplish this is by employing arrays.

- Use _FileReadToArray to read your Test.txt file, then use it to read TestCopied.txt

- Merge the two arrays into one (_ArrayConcatenate)

- get the unique elements from the big array (_ArrayUnique)

- write the result array to TestCopied.txt (_FileWriteFromArray)

Job done :huh2:

It worked ;)

Thanks!

Link to comment
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
 Share

  • Recently Browsing   0 members

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