You have to login in order to post a reply to this topic.

3 replies [Last post]
Andrew
Andrew's picture
User offline. Last seen 1 year 25 weeks ago. Offline
Joined: 03/12/2010
Posts: 33

Hello,

 

As part of a WinAutomation (version 3.03.410) job, I am trying to retrieve all the folders named "Projects" within a directory into a list of folders to be processed later.  The methods I have tried so far:

 

Method 1: First create an empty list and use the "Get SubFolders in Folder" action with "Include Subfolders" checked.  Then, "For Each" folder in the list, use "Parse Text" on the folder name to see if it is called "Projects".  Add any folders with the name "Projects" to the empty list. 

Problem--the result is a "List of General Values" because the preprocessor doesn't know that I only added Folder variables to the list, so a later action to get the name of one of the folders in the list causes a preprocessor error.

 

Method 2: Use the "Get SubFolders In Folder" action with "Include Subfolders" checked.  "For Each" folder in the list, add the index of any folders not called "Projects" to a list of numbers.  Then, for each item in the list of indexes, use the "Remove Item from List" action on folder with the specified index.

Problem--each "Remove Item from List" action modifies the list so the indexes don't match the item they originally did.

Listed below are some actions I didn't see that I think would solve my problems with Method 2:

1) "Get Index of Item"--accepts a list and an item to search for, and returns either the first index of an item (-1 if the item does not exist) or a list of indexes of items that match (an empty list if no matches are found).  I can make this happen using a nested "For Each" loop, but it won't be efficient.

2) "Sort List Descending"--the current "Sort List" action only accepts a single list argument.  I didn't test it, but I imagine it only sorts in one direction.  If I could sort my list of indexes in descending order, "Reomve Item from List"

3) "Remove Item(s) From List"--accept either one or several indexes of items to remove from a list (probably implemented by sorting the indexes in descending order).  If one of the items does not exist, none of the list items are effected and an error message is returned.

 

I heard WinAutomation 3.1 is in beta testing right now--it would be nice if some of these actions were addressed in this or a later version of WinAutomation.

 

Edi: I also tried "For Each" member of the list of folders, if the name fo the folder isn't "Projects", remove the folder from the list directly inside of the loop (without storing a separate index list).  After the "Remove Item from List" action, the action to reach the next folder in the list of folders failed.

An "If List Contains" [item] action would also solve my problem.

Andrew
Andrew's picture
User offline. Last seen 1 year 25 weeks ago. Offline
Joined: 03/12/2010
Posts: 33
Re: New List Actions

Actually, what I am discovering I really need is a "Merge Lists" action, that accepts two list parameters (that must be of the same type) and returns a third list of the same type containing all the items in both of the first two lists.

 

I resolved my issue from before somewhat more efficiently by using an "Exit Loop" action inside of a nested loop structure designed to get the index of the first item encounterd.

 

However, next I need to combine all the subdirectories of the "Project" folders into a single list of subdirectories, and then check the names of the folders to see if they have a certain syntax--so I need the list of subdirectories to be treated as a "List of Folders" instead of a "List of General Values".  I'm not sure how I can accomplish this without a "Merge Lists" action.

D.M.Altizer
User offline. Last seen 1 year 11 weeks ago. Offline
Joined: 01/12/2010
Posts: 204
Re: New List Actions

 Have you tried the "Find Common List Items" action under "Variables Actions" category? If this does not suit your needs, please describe what is the problem with the specific action so that we will be able to understand exactly what you are trying to do.

__________________

==Dedicated Automation Solutions==

__________________

==Dedicated Automation Solutions==

Andrew
Andrew's picture
User offline. Last seen 1 year 25 weeks ago. Offline
Joined: 03/12/2010
Posts: 33
Re: New List Actions

Not quite what I was looking for--basically I want a "Union Lists" action--or what I was describing as a "Merge Lists" action which includes duplicates in the union as duplicates in the result list (I suppose "Add Lists" or "Append List" would be a more appropriate name).  I also want the action to create the list after the Union or Append occurs having the same data type as the original two lists--which the "Add Item to List" action wasn't doing when I used it before.  "Find Common List Items" appears to take the intersection of two lists.  Sorry I wasn't more clear.

 

Edit:  There may be a bug in the "Add Item to List" action.  It appears that I can add a "Folder" item to a list of folders, and the result will be a list of folders.  However, adding a folder to an empty "list of general values" does not cause the list to become a "list of folders" as I would expect, but leaves it as a "list of general values".  I think "Add Item to List" would work better if adding any object to an empty list caused the data type of that list to match the type of the new object.  Then adding a variable of a different type would change the list back to a "list of general values", or possibly cause an error message.