Iterate through text file

Questions and answers on how to get the most out of FFAStrans
Post Reply
molped
Posts: 3
Joined: Wed Jan 30, 2019 11:32 am

Iterate through text file

Post 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
admin
Site Admin
Posts: 1687
Joined: Sat Feb 08, 2014 10:39 pm

Re: Iterate through text file

Post 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 3396 times
foreach.png
foreach.png (7.56 KiB) Viewed 3396 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
molped
Posts: 3
Joined: Wed Jan 30, 2019 11:32 am

Re: Iterate through text file

Post 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 3379 times
The populate node should read lines from the text file TV.txt.
2.png
2.png (10.99 KiB) Viewed 3379 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 3379 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!
admin
Site Admin
Posts: 1687
Joined: Sat Feb 08, 2014 10:39 pm

Re: Iterate through text file

Post 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
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Iterate through text file

Post 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
emcodem, wrapping since 2009 you got the rhyme?
molped
Posts: 3
Joined: Wed Jan 30, 2019 11:32 am

Re: Iterate through text file

Post 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!
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Iterate through text file

Post 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.
emcodem, wrapping since 2009 you got the rhyme?
Post Reply