09-16-2016 05:28 AM
Bonjour à tous,
Je souhaite faire plusieurs tests sur le nom d'un fichier et notamment s'il est valide ou pas. Sa création provient d'une concaténation de variables chaînes par exemple ...\OF\n° série\nom.xls
Si l'OF est vide j'obtiens en chaine : ...\\n° série\nom.xls je suis capable de regarder si j'ai 2"\\" qui se suivent et dans ce cas j'en conclus qu'une variable en entrée est vide. Mais dès que je convertis la chaine en chemin pour faire d'autres tests (fichier existant ou pas etc) automatiquement ...\\n° série\nom.xls devient ...\n° série\nom.xls et du coup mon test ne fonctionne plus. Comment empêcher cette suppression de "\" ?
Merci pour vos retours
09-16-2016 06:11 AM
It's difficult to translate for me, but why you don't use "search and replace"?
09-16-2016 08:11 AM
Hello Artem,
I translate into English my problem.
When I concatenate strings like "..." + "/" + "empty" + "/" + "SN" I have this result : ...//SN
When I look for "//" I understand a string is empty => correct behavior.
When I convert string to filepath I obtain .../SN instead of ...//SN so my test never works.
I do not understand why Labview automatically cancels the 2nd "/". So I never can say when a string is missing...
Any ideas?!
09-16-2016 08:22 AM - edited 09-16-2016 08:31 AM
Hi Diane,
why do you concatenate strings to create a filepath? There are filepath functions available!
Edit after checking our VI:
- I never had any windows filepath with a double backslash in it!
- You are looking for 3 backslashes, then you compare with 2 backslashes - can you explain this?
- As you look for a regular expression you should type in 4 (!) backslashes, when you want to find a double backslash in your file path string! (Escape aka backslash-codes are explained in the help for the SearchString function…)
09-16-2016 08:24 AM
Could not recreate..!
09-16-2016 08:46 AM
Hi GerdW
Data like SN come from user that is why I am using strings.
Having the test in my subVI allows me to validate filepath everytime I am using filepath. I don't want to copy my test each time I create a filepath.
09-16-2016 08:52 AM
What operating system are you using?
On windows, you should be using backslashes \. But you are using forward slashes /.
If you are trying to create a path, then you should use the Build Path functions rather than concatenating strings.
Also, why are you trying to put an empty string in between the two slashes?
09-16-2016 08:53 AM - edited 09-16-2016 08:54 AM
Hi Diane,
When I concatenate strings like "..." + "/" + "empty" + "/" + "SN" I have this result : ...//SN
When I look for "//" I understand a string is empty => correct behavior.
Why do you look for "\\" in your concateneted filepath/string? Why don't you look for this "empty string" before concatenation? Why don't you disable/disallow empty strings in the filepath building process?
Having the test in my subVI allows me …
Having a subVI is fine - no need to excuse for!
09-16-2016 09:01 AM - edited 09-16-2016 09:02 AM
Hi,
If I have to guess what's happening on the path input, sometimes you may end up inputting: "C:\Test\\Ser_Num\" where \\ means that an input is "missing" and you want to replace the \\ with \.
If this is the case, then as GerdW mentioned, you should search for \\\\ to find \\ and replace.
edit - but as GerdW mentioned, there are easier ways of eliminating empties before building them into a path.
09-19-2016 01:45 AM
Hi GerdW,
Yes checking empty values before concatenation could be a solution but I had to do it for each variable and each time I concanate so for me I duplicate code... As I often call my sub VI I prefer to do the test inside, once.
If I find "\\" I just want to warn, I deduce a value is missing I don't need to replace it. But when I convert string data to filepath I loose the "\\" and automatically just have "\"... Some options in the filepath command are activated? I didn't find anything for the moment...