Old problem, new eyes - users and special characters in paths?

Hi folks,

In dealing with the wonderful world of filenames allowed by Apple, I’m faced again with an issue. I had changed the way that two of my apps deal with CSV files to use the pipe symbol “|” instead of the comma since customer use commas (and • and & and * and … you get the picture) in file names. This has worked for many years - until this weekend when I’ve learned that on audio app (Pro Tools) allows the use of the “|” symbol in file names.

Here’s my question - I receive a line of text from the specified file that looks like this:

VL:x|5031936|0|5320013|0|./My Documentary Deliverables/Ringworld Architects | World Series/Viva Hate/12 Dial-A-Cliché.mp3

Note that the path has the “|” embedded in one of the folder names (you may need to scroll horizontally). Therefore, when I SplitB that, I end up with 7 fields instead of the expected 6. The only workaround I’ve come up with is to get the UBound of the SplitB array, and if it’s more than 6 (index 5), I add the | back in and then append the next array value.

This works, but since users are so creative, my quandary is how many If entries do I account for beyond pathPart(5)?

It’s my hope that there’s a blue pill out there that will let me handle this without needing to potentially account for 10+ “|” symbols in the path :woozy_face:.

Ideas?

Use a chrb(0) as your delimiter instead?

You could use regex for this too… @Kem_Tekinay ?

This pattern should do it:

^((?:[^|]*\|){5})(.*)

Take the result in SubExpressionString( 1 ) and Split it by the bar, then tack on the value in SubExpressionString( 2 ).

But I’d probably create a function that splits, then combines all the elements starting at index 5.

1 Like

My advice is to properly escape any special delimiter characters in the csv file. Otherwise, you’ll spend the rest of your life fixing your code whenever someone finds a novel new way to name files. Code for properly reading and writing csv files (with proper escaping) has been posted here in the past.

2 Likes

You should really enclose strings in quotes as “string”, and if needing embedding a quotation mark, double it as in Xojo as “this is ““quoted”””, so you can have strings as “my file * ! jshf, ||| whatever .txt”

If I created the CSV file, that would be the solution, but it’s based on filesystem output.

That’s where I finally went this morning.

I have used tab separated for years. Spares all the fuss about users inserting comma or semicolon, as well as quotes.

1 Like

You mean that people create such CSV using external tools you can’t control, and they control just the field separator?