How to Count a list of URLs stored in a Variable
Moderators: Dorian (MJT support), JRL
How to Count a list of URLs stored in a Variable
Hi did due diligence combing thru forums and found no referrences to solving this.
I have a variable that contains anywhere from 1 up to 5 URLs separated by ';' (using the SEPARATE command)..
What I want to do is count the number of urls and execute IF/Else statements based on the number of URLs found?
I was thinking about using a Read Line function but I'm so new to this I don't know if that would be barking up the wrong tree...
Ideas?
Thanks!
I have a variable that contains anywhere from 1 up to 5 URLs separated by ';' (using the SEPARATE command)..
What I want to do is count the number of urls and execute IF/Else statements based on the number of URLs found?
I was thinking about using a Read Line function but I'm so new to this I don't know if that would be barking up the wrong tree...
Ideas?
Thanks!
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
The Help is your friend this is the example code. Separate reads the file names into an array called file_names and file_names_count will automagically contain the number of items.
GetFileList>c:\temp\*.*,files
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Message>file_names_%k%
Until>k,file_names_count
Label>end
GetFileList>c:\temp\*.*,files
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Message>file_names_%k%
Until>k,file_names_count
Label>end
Ahhhh... thanks! Will check help first next time!
Me_again wrote:The Help is your friend this is the example code. Separate reads the file names into an array called file_names and file_names_count will automagically contain the number of items.
GetFileList>c:\temp\*.*,files
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Message>file_names_%k%
Until>k,file_names_count
Label>end
Hello Me_Again, so I tried to use this code right out the box. Substituted c:\temp for the correct path of my file. Tried both the GetFileList and ReadFile functions and both will capture contents into variable. The SEPARATE command delimits just fine.
But, the MessageModal line returns a value of 1 and I know that there are 5 items in the list.
Any ideas?
What I'm trying to do is read a text file with anywhere from 1 to 5 URLs and based on the number of URLs, execute a serious of IF statements.
e.g.
IF>URLcount=1
do something
If>URLcount=2
do something else
etc..etc...
But, the MessageModal line returns a value of 1 and I know that there are 5 items in the list.
Any ideas?
What I'm trying to do is read a text file with anywhere from 1 to 5 URLs and based on the number of URLs, execute a serious of IF statements.
e.g.
IF>URLcount=1
do something
If>URLcount=2
do something else
etc..etc...
Me_again wrote:The Help is your friend this is the example code. Separate reads the file names into an array called file_names and file_names_count will automagically contain the number of items.
GetFileList>c:\temp\*.*,files
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Message>file_names_%k%
Until>k,file_names_count
Label>end
Hi clickfast,
If you are reading the contents of a single file you'll need to modify the example slightly. Instead of using GetFileList>, which reads a directory and creates a list containing the names of all the files located in that directory, try using Readfile> which will read the contents of a particular file.
If you are reading the contents of a single file you'll need to modify the example slightly. Instead of using GetFileList>, which reads a directory and creates a list containing the names of all the files located in that directory, try using Readfile> which will read the contents of a particular file.
Code: Select all
ReadFile>C:\Path\URL_List_Filename,;,URL_List
MessageModal>Num URLs: %URL_List_count%
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Message>URL_List_%k%
Until>k,URL_List_count
Label>end
Sorry Guys, I just can't get any of these to work. So I'm pasting the source of my test file.
Copy and past the following dummy URLs into a .txt file and name it urls.txt and save it to c:\
Then try to use the following script based on recommendations in this thread.
[/quote]
I can't get this to work using the above .txt file and the script above.
Copy and past the following dummy URLs into a .txt file and name it urls.txt and save it to c:\
Then try to use the following script based on recommendations in this thread.
Code: Select all
ReadFile>C:\urls.txt,;,URL_List
MessageModal>Num URLs: %URL_List_count%
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
Message>URL_List_%k%
Until>k,URL_List_count
Label>end
I can't get this to work using the above .txt file and the script above.
JRL wrote:Hi clickfast,
If you are reading the contents of a single file you'll need to modify the example slightly. Instead of using GetFileList>, which reads a directory and creates a list containing the names of all the files located in that directory, try using Readfile> which will read the contents of a particular file.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
You aren't using GetFileList> which is a special case because it produces a ";" delimited output. With ReadFile>, even with Bob's fix, all you have done is read the whole list of URL's into a variable. To display them separately you'll need to separate them and you can do that with the CRLF that's between the lines of the original file:
ReadFile>C:\urlstest.txt,URL_Text
MDL>URL_Text
Separate>URL_Text,CRLF,URL_List
MDL>%URL_List_count%
Let>k=0
Repeat>k
Let>k=k+1
MDL>URL_List_%k%
Until>k,URL_List_count
Label>end
ReadFile>C:\urlstest.txt,URL_Text
MDL>URL_Text
Separate>URL_Text,CRLF,URL_List
MDL>%URL_List_count%
Let>k=0
Repeat>k
Let>k=k+1
MDL>URL_List_%k%
Until>k,URL_List_count
Label>end
The question below is answered in this post http://www.mjtnet.com/usergroup/viewtopic.php?t=3922
So now I'd like to perform a few IF statements based on the number of URLs.
Example
IF the URL Counts =1 then do something
If the URL Counts = 2 then do something
If the URL Counts = 3 then do something
etc...
What is the best way to structure this? Also, how do I pass the %URL_List_count% variable to the IF statements?
Thanks!