Create new filename for list of files

In the workflow I list the xml files in a folder. Then in the xml files data need to be changed. Reformat the data to xml again.
And finally I like to save these files with the orginal filename with extra “_b” at the end of filename in another folder.

Until the string to xml part it is oke, but
Can someone let me know how to do the part of renaming the files after the “String to XML” node and save to another folder? At the moment all files get the same name “row0.xml”

Hi @RonG,

the XML Writer uses the RowID of each row for the filenames (that’s what it says in the node description). You can use the RowID Node to pick a column to replace the rowid.

I would extract the Location flow variable inside your loop to a column, then extract the filename and append your suffix, then merge that back into your data branch. Add a RowID node and pick your filename column to replace the current RowID. Configuration will look similar to this:

1 Like

Hi Johannes,

thanks for your reply, but I’ am still struggling.
I can’t find where and how to do this **“I would extract the Location flow variable inside your loop to a column, then extract the filename and append your suffix, then merge that back into your data branch.”
Your steps sounds logical, but I can’t find the solution. I have only these flow variables in the “Table Row to variable Loop start” module
image

Okay, the Flow Variables tab in the node shows you three things: The settings of the node (e.g. CFG_FAILONMISS), a dropdown to set this setting dynamically with a flow variable and a textfield if you want to write this setting to a flow variable. We don’t need any of this.

If you execute the Table Row to Variable Loop Start and open the table output, there is also a flow variables tab. This shows all the flow variables this node outpus for one iteration. Should look sth like this:

The Location is the path of the xml file (The Loop takes each row of the list files and turns them into flow variables). You connect a Variable to Table Column node to that and then you have your Location flow variable in a column. Then use String Manipulation to extract the filename (lastIndexOf(…,"/")) and add your suffix ("_b).

Try it out and let me know at which part you are struggling.

Hi Johannes,

I do something wrong.
This are the nodes
image
This is the outcome of Table Row to Variable Loop Start

But in the Variable to Table Column node there is no data available
image

What am I missing or do I wrong?

Thanks,

Ron

You have to connect a data table to the variable to table column node.

Hi Johannes,

This is the workflow at the moment:


So in the purple rectangle is the new filename created.
image

But I have tried to combine the data of the file and the filename with a column Appender but did not succeed in replace the Row0 with the filename in the xml file. Still there is only one file created with Row0.xml as name.

do you have another suggestion

Thanks

Ron

Hi Ron,

can you upload your workflow, then I can have a look.

Hi Johannes,

this is the workflow sofar
Echo XML file replace UnknownBarCode simple.knwf (35.3 KB)

Also uploaded 3 xml files with unkownbarcode in the file
Echo_Raw-Echo_Transfer-Echo555_O01_7182729-21097.xml (144.3 KB)
Echo_Raw-Echo_Transfer-unknown destination.xml (152.7 KB)
Echo_Raw-Echo_Transfer-unknown source.xml (152.7 KB)

I like to load all xml files from a folder and check if there is a “unknownbarcode” in the xml file. If so replace by a new barcode value. Then write xml file with “_b” to filename in same or another folder (“corrected files”)
Thanks,

Ron

Ok. It turned out to be more work than I expected. Mostly because the XML Writer does only accepts rowIDs as filenames which is ugly. The wf now goes like this:

  1. It extracts the current Location variable from the Table Row to Variable Loop start as a column (because then we can pass it to the rowID later.
  2. Does some string manipulation to get the right filename (You had most of the work right there).
  3. It joins the table of the xml together with the new filename and passes that on to the RowID and to the xml writer.

Echo XML file replace UnknownBarCode simple2.knwf (45.6 KB)

1 Like

Hi Johannes,

I will have a look at the workflow and try to understand it.
Let you know if I have looked at it.

Already thanks a lot for your effort

Thanks,

Ron

Hi Johannes,

the workflow is clear to me. The only thing in the workflow that is not doing the job is the part of retrieving the filename from the Location.
the lastindexofchar command does not work with ‘\’. it does work with a character.
image
Is there another way to do this?

Thanks,

Ron

Hi Johannes,

it looks like you need to put a double \\ in there. the first one is skipped. Now it works fine.
You even have to put a double \ in this box . A single \ is just skipped and not in the message.

Thanks,

Ron

Hi Ron,

for me the Location looks like this: /home/jschweig/Downloads/Refresh button2.png (I am on Linux). If I remember correctly Windows uses backslashes \ for its paths which have to be escaped.