Page 1 of 1

Iterate through text file

Posted: Sat May 21, 2022 12:29 pm
by molped
Hi!

I have a text file containing lines with paths and filenames.
I would like to iterate though this text file, extract each path+filename and do some processing on each file.

How do I do that?

Br

Re: Iterate through text file

Posted: Sun May 22, 2022 9:25 am
by admin
Hi molped, thank you for using FFAStrans and welcome to the forum! :-)

If your text file purely consists of paths separated with a new line then it's quite easy:
First you must use a "Populate" node to populate a user variable with the readout of your textfile. Then you connect a "Foreach" node to dynamically create branches for each path:
pop.png
pop.png (7.66 KiB) Viewed 3398 times
foreach.png
foreach.png (7.56 KiB) Viewed 3398 times
Note that in the "Foreach" node it says "Array string" but it will also accept the kind of text you're supplying with new line separated paths. Try it and report back :-)

-steinar

Re: Iterate through text file

Posted: Mon May 23, 2022 11:25 am
by molped
Hi steinar,

Thank you for helping!

I tried setting up a test workflow:

A populate node, a for-each and a command executor, thats runs a batch file which will do some work.
1.png
1.png (5.02 KiB) Viewed 3381 times
The populate node should read lines from the text file TV.txt.
2.png
2.png (10.99 KiB) Viewed 3381 times
The for-each stores the read lines into %s_source% which is then fed into the command executor.
3.png
3.png (10.34 KiB) Viewed 3381 times
It seems that nothing happens - am I missing someting?


Thank you - and keep on the good work on making this great tool even better!

Re: Iterate through text file

Posted: Mon May 23, 2022 12:51 pm
by admin
I see you have no monitor for triggering input sources. Do you use manual submit via GUI or the API? The populate node itself does not do anything itself until it's triggered. If you have neither, you can just submit a bogus file to the workflow just for triggering.

-steinar

Re: Iterate through text file

Posted: Mon May 23, 2022 1:29 pm
by emcodem
example workflow. Submit any file to the text file processor, it does not matter which file you submit as the workflow discards it and instead automatically writes a text file to simulate your input text file.
emcodem_foreach_newline.json
(3.67 KiB) Downloaded 209 times

Re: Iterate through text file

Posted: Wed May 25, 2022 11:57 am
by molped
I inserted a monitor node, and it works!

Is it possible to trigger a workflow eg. on a set time of day?

Thanks for your help!

Re: Iterate through text file

Posted: Wed May 25, 2022 12:20 pm
by emcodem
Hehe yeah something has to trigger the workflow, be one a monitor processor, manual submit, api...
The webinterface has a scheduler builtin that allows you to trigger workflows based on a specific frequency. When you do that in high frequency, e.g. every minute, you want to make sure that you delete the job from the logs after it is finished successfully. See last comments in the webinterface forum thread.