Text export (CSV) problem

Started by jonz, May 13, 2023, 03:32:53 AM

Previous topic - Next topic

jonz

I can't figure out why certain photos in IMatch generate a CSV record that breaks into several lines on import into other programs. I'm using text export to generate captions for Affinity Publisher, but it doesn't matter where they are going - the csv file is breaks records where it shouldn't. I would say that there are line feeds being generated after certain fields but I don't see why.
When I import the CSV into a text editor (text_editor version 1) you can see that the first record imports properly, the second and third records split into three lines each, and then the next two records are correct. So lines 1, 8 & 9 represent records (photos) that are exporting from IMatch properly, and lines 2-7 are breaking so the fields are in the wrong positions. I've manually edited the CSV file in version 2 (text_editor version2) so it's the way it should be.
I can't figure this out. There isn't a delimiter in the text fields, and I don't see anything that's wrong technically with what I'm doing, but obviously something is wrong. Does anyone see what it is? (sorry, corrected version wouldn't upload because I have six files).
Thanks very much.

Mario

Quote(sorry, corrected version wouldn't upload because I have six files).
Just put all files into a ZIP, which makes one upload file.

Your description field (most likely) contains new line characters or even carriage-return / line-feed pars (hexadecimal 0x0A, 0x0D) and this makes the CSV break lines in the middle of a row.
CSV files use 0x0A,0x0D as line delimiters (if you use the default {cr}{lf})


To test: Select the text of a description tag (click into it in the MD Panel, press Ctrl+A and Ctrl+C to copy it into the Windows clipboard. Paste it into Windows Notepad. If it is not one long line but breaks into multiple lines, you've found the culprit.

You add line feeds to metadata by pressing <Shift>+<Enter> or <Ctrl>+<Enter> in an editor or the Metadata Panel. Maybe the characters were already in the data when you imported the files into IMatch. It is not uncommon to add line breaks to tags which hold longer texts, like description.

CSV files are not designed to deal with carriage-return or line-feed characters or other special characters.
You could use another record delimiter for the Text Exporter, but that depends on the importing application.

What I would do is to use the replace variable function to replace 0x0A, 0x0D with "nothing" or a blank character to make the text flow into one line:

{File.MD.description|replace:{cr}==;replace:{lf}== ;}

The special {cr} and {lf} tokens IMatch supports can be used for that.
This variable replaces carriage-returns in the description with "nothing" and line-feeds with a blank.

Use it with the Text Exporter.
If this does not fix the problem, the CR/LF are in another tag and you need to find out which one.

Tip: If you want to see if a variable value contains 0x0A or 0x0D, you can use this variable:

{File.MD.description|replace:{cr}==CR;replace:{lf}==LF;}

instead in the VarToy. If shows CR for each carriage-return and LF for each line-feed.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

jonz

Thank you so much Mario, you nailed it. It should have occurred to me but sometimes I was pasting text in and I must have been including the line feed without realizing it. I still love the program after all these years. JS