I had a consistent crash that I removed yesterday (and I never was able to know why *). The code do:
Let the user choose a Source text file
Let the user choose a Target directory
Read the Source text file contents and use each line to create a Child directory into the Target directory.
Then, when the new directory is created, I add a Text file in it using the just created folder and close it. The crash occured there.
That code is in a Try block.
I noticed: the | character crash the program flow.
I also noticed that at some stage a “:” existed at the end of the read string in the code flow, not in the Text file. I know this because my directories had an ending " - "
(I replace automatically any ‘:’ by ’ - ').
So, is there’s a built-in way to avoid OS Gremlins characters to be passed to create a directory, an item (here a Text file) on Windows ? **
Of course, beside using ReplaceAll ?
TIA
- I modified the original code so much that I really do not know why it was crashing earlier. Oh ! That code worked fine on OS X !
In fact it was far more than a refactoring.
** The only gremlin character on OS X is :, so it is easy to replace it.
[quote=218605:@Emile Schwarz]I had a consistent crash that I removed yesterday (and I never was able to know why *). The code do:
Let the user choose a Source text file
Let the user choose a Target directory
Read the Source text file contents and use each line to create a Child directory into the Target directory.
Then, when the new directory is created, I add a Text file in it using the just created folder and close it. The crash occured there.
That code is in a Try block.
I noticed: the | character crash the program flow.
I also noticed that at some stage a “:” existed at the end of the read string in the code flow, not in the Text file. I know this because my directories had an ending " - "
(I replace automatically any ‘:’ by ’ - ').
So, is there’s a built-in way to avoid OS Gremlins characters to be passed to create a directory, an item (here a Text file) on Windows ? **
Of course, beside using ReplaceAll ?
TIA
- I modified the original code so much that I really do not know why it was crashing earlier. Oh ! That code worked fine on OS X !
In fact it was far more than a refactoring.
** The only gremlin character on OS X is :, so it is easy to replace it.[/quote]
The alternative to replacing illegal characters is to prevent the user to enter them in the first place. Something in Keydown with or without a punishing beep are to do it.
For more about replaceall and the list of characters, look at https://forum.xojo.com/24840-create-folder-not-creating-folder
IMHO the best option is to use a replaceall as what I posted there. But you can also use encodeURLComponent which will replace invalid characters by % things.
You can also use a Try Catch structure to trap the IOException. But that is kind of messy. It will force the user to correct his entry.
Thank you for your anser Michel. Still in NY ? Went to the John Lennon birthday yesterday at Central Park ?
No, I cannot do that since the data comes from a text file that can be created elsewhere (or not).
I strongly dislike getting %DD in my file names.
So if no simple solution, I will trap the illegal characters in a Function using ReplaceAll and place an underscore character.
This is already in a Try Catch structure, but I want to create folders / save text file with text.
My memory had something on the subject, but not what Michel pointed to me. I recall (while reading) fine this conversation, now.
I will do that.
That is more what I had in mind (and I recall haveing seen a solution - what Michel wrote):
Windows Illegal Characters.
Unfortunately, earlier today, my brain was still in sleep mode and it does not comes back.
Thanks.
Note that using astute replacements, you may obtain file names that are looking close to the original :
dim a as string
a=str(d.AbbreviatedDate)+" at time "+str(d.ShortTime)
a=a.ReplaceAll(",","-")
// Illegal characters Windows / ? < > \\ : * | "
a=a.ReplaceAll("/",&u2044) // Fraction
a=a.ReplaceAll("?","¿")
a=a.ReplaceAll("<",&u2039) //LeftSingleGuil
a=a.ReplaceAll(">",&u203A) //RightSingleGuil
a=a.ReplaceAll("\","`") //Grave
a=a.ReplaceAll(":",";") // Semicolon
a=a.ReplaceAll("*","x")
a=a.ReplaceAll("|",&u2502) // semigraphic single vertical bar
a=a.ReplaceAll(chr(34),&u201D) // QuoteDBLRight
PS : I am back in Paris. Tried to bring back some sun, but it did not last 
Same kind of weather in Strasbourg (Autumn leaves
).
To avoid a problem like this it is worth writing a nice methode for the personal library.
Care to expand the explanation ?