Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Reading a folder tree recursively
Topic Summary: Recursion
Created On: 08/26/2013 01:09 PM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 08/26/2013 01:09 PM
User is offline View Users Profile Print this message

Author Icon
CaseyHarris
Journeyman (50-99)

Posts: 62
Joined: 07/15/2013

Greetings,I am attempting to figure out how to recursively read a directory tree. I've created and tested the following code, which is obviously not correct, since it ends up in an infinite loop. Also, when I click Cancel to stop the task, it throws a rather ugly excpetion. (At least that is what happened to me when running Automate 8, on Windows Server 2008 R2 64-bit).I am not concerned about the exception (though NA support may be), I am more interested in how to accomplish the recursion.Thanks in advance.Casey

 Category Survey



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
Thanks,

Casey
 08/26/2013 08:57 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

If ScanFolderTree is the task itself, then each recursion starts the task anew, since it refers always to I:\Casey\Test\*.*, then it creates an infinite loop.
You could find a means to pass the subfolder target name (item) to the called task into a variable (e.g. startItem).
Inside the task the variable startItem should be declared as parameter, with the initial value I:\Casey\Test
This way the tasks will scan the tree instead of starting anew each time.

I don't think the start managed task action can accept parameters.
But if you run from AMRUN AMTask.exe with parameters it could do it. Something like
"c:\Program Files\Automate 8\AMTask.exe" "c:\thetaskfilefolder\ScanFolderTree.aml" /var:startItem=%item%

 Category Survey
AutoMate 8 version:
Windows version:



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 08/27/2013 08:18 AM
User is offline View Users Profile Print this message

Author Icon
CaseyHarris
Journeyman (50-99)

Posts: 62
Joined: 07/15/2013

Hi Jean,Thanks very much for your reply; I will give your suggestion a try. You are correct, ScanFolderTree is the name of the task.I know that the paramter is the key, since it will be used as the start value for the subsequent iterations, but I was not sure how to pass a parameter from one task to another. (Though I have seen it done using an external file as the mechanism.)If I make the ScanFolerTask an unmanaged task, is there a way to pass in a parameter?P.S. Does anyone know how to change this forum message text editot so that it displays my messages properly, instead of in a single stram? It's almost as though all formatting has been turned off.Thanks,Casey

 Category Survey


-------------------------
Thanks,

Casey
 08/27/2013 10:00 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Casey,
in your forum profile, in Personal options, select the HTML editor. I think it will improve the appearance.
In Automate, each managed task has its own aml file. Passing a parameter to run an aml file can be done as I explained in my latter post, using the AMRUN action to invoke AMTask.exe. Did you have a try to it ?
You can still have it as a managed task to scan from the root folder as you did.

 Category Survey
AutoMate 8 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 08/27/2013 08:22 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

BTW, why do you need to run the task recursively?
AM tasks have the capability to create custom functions inside the task, that you can call at will.
Also looping all the sub-folders of a folder is feasible using the Loop Files action as below.
Considering these two capabilities could help solving your problem more easily.

 Category Survey
AutoMate 8 version:
Windows version:



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 08/28/2013 01:46 PM
User is offline View Users Profile Print this message

Author Icon
CaseyHarris
Journeyman (50-99)

Posts: 62
Joined: 07/15/2013

Hi Jean,

Thanks again. I have not gotten a chance to try it yet, but I will.

 Category Survey


-------------------------
Thanks,

Casey
 08/28/2013 01:49 PM
User is offline View Users Profile Print this message

Author Icon
CaseyHarris
Journeyman (50-99)

Posts: 62
Joined: 07/15/2013

Hi Jean,

I did not realize that Loop Files would give me the contents of a folder (I did not realize that it processed folders). If it will, then it will meet my need.

I will do some more more testing.

Thanks for your assistance.

EDIT: I briefly forgot my need. Recursion is necessary because I don't know in advance how many levels deep the folder structure will be - it could be 1, or it could be 3. Realistically. it should not be more than one or two, but I cannot be sure in advance.

 Category Survey


-------------------------
Thanks,

Casey

Edited: 08/28/2013 at 01:56 PM by CaseyHarris
 08/28/2013 10:26 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

The loop files including sub-folders goes to any depth as necessary. It scans all sub-folders, sub-sub-folders, etc No need to specify it.

 Category Survey
AutoMate 8 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 1261 guests browsing this forum, which makes a total of 1261 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2020 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog