Noob question - going down a list

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Shevs
Newbie
Posts: 6
Joined: Thu Jan 17, 2013 11:27 pm

Noob question - going down a list

Post by Shevs » Fri Jan 18, 2013 1:48 am

Hi, so I have a list of files in a folder that I need to go through and execute one by one. I think I have everything else figured out.

It can not simply switch to the folder and press the down key once. Occasionally after executing one of the items on the list, the list will change. So I was hoping for a way that it could retrieve the list of files within the folder, then go down the list, and stop when the list ends.

How would I go about doing that?

Thanks

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri Jan 18, 2013 5:49 am

I would do something like this, however it depends on what your wanting to execute. If your wanting just exe's (programs) change *.* to *.exe

If its files you might need to replace the RunProgram with execute file.

Hope this helps.

Had to post script to pastebin as it wasn't being formatted correctly on the forum even with the code tags.

PasteBin Link To Script
FIREFIGHTER

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Jan 18, 2013 4:35 pm

The GetFileList Help topic has a good sample to use.

When you mention the list may change as you are running this script, that increases the complexity quite a bit. That indicates you will need to do something like this:

Code: Select all

Create file list   (GetFileList)
Separate into array
Get FileListCount
Create an AlreadyRunList   (blank to start with)
Set counter = 0

Loop until counter=FileListCount
  Let>counter=counter+1
  Read item(counter) on file list 
  Check AlreadyRunList to see if file has been run 
  If file has not been run
    Run the file
    Add to file 'AlreadyRunList'
    Recreate the file list
    Separate into array
    Get FileListCount
    Let>Counter=0   (When the list is recreated you start at the top again)
  Endif
Endloop
Thanks,
Jerry

[email protected]

Shevs
Newbie
Posts: 6
Joined: Thu Jan 17, 2013 11:27 pm

Post by Shevs » Fri Jan 18, 2013 7:54 pm

Thanks guys, much appreciated. Your example makes sense, Jerry, but where is the list actually created? Is this something I can actually see? Is it put into the 'watch list' tab?

This was in the help topic -

GetFileList>C:\Documents and Settings\vanderwey\Desktop\xFund 12-31-12,strFileList,;
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%
Let>k=0
Repeat>k
Let>k=k+1
Message>file_names_%k%
Until>k,file_names_count

I'm unsure of what the 'k' stuff is doing. Is K the number of the file on the list?

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Jan 18, 2013 8:54 pm

The list is the array of file_names.
The list of file names will show in the Watch List.
The sample you copied goes through the list and shows the names of the files.

For your script, you would just change the "Message" line to
Run>file_names_%k%

'k' is the counter that starts at 0 and goes up to file_names_count.
(by default, arrays start at 0)
The percent sign is how you can combine a variable name and an indicator.
file_names_0 is the same as file_names_%k% when k=0

The loop keeps you from having to repeat a line like this
Message>file_names_0
Message>file_names_1
Message>file_names_2
Message>file_names_3
etc.
Thanks,
Jerry

[email protected]

Shevs
Newbie
Posts: 6
Joined: Thu Jan 17, 2013 11:27 pm

Post by Shevs » Fri Jan 18, 2013 9:29 pm

Hmmm, I'm having trouble having it find the correct file, it keeps giving me an error. I used the 'Run>file_names_%k% '

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Jan 18, 2013 11:25 pm

My mistake, the array above starts at 1 not 0!

Look in the WatchList
Is file_names_1 showing the correct location and file name?
Thanks,
Jerry

[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts