LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Test chemin valide

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

 

 

0 Kudos
Message 1 of 11
(5,024 Views)

It's difficult to translate for me, but why you don't use "search and replace"?

path.png

0 Kudos
Message 2 of 11
(5,010 Views)

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?!

0 Kudos
Message 3 of 11
(4,989 Views)

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…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(4,984 Views)

Could not recreate..!

0 Kudos
Message 5 of 11
(4,980 Views)

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.

0 Kudos
Message 6 of 11
(4,971 Views)

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?

0 Kudos
Message 7 of 11
(4,967 Views)

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!

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(4,966 Views)

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.

0 Kudos
Message 9 of 11
(4,956 Views)

Hi GerdW

 

0 Kudos
Message 10 of 11
(4,922 Views)