LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to check string control to see if it has a valid windows file name (no illegal characters like * / > " : |).

Oops, as Kenny K has mentioned, we may have spoke too soon.  It seems the posted code needs a little tweaking.  I am working on it, trying to figure it out.  But it is a very good start.

Thanks everyone!

0 Kudos
Message 11 of 38
(2,672 Views)
It appears it seems to be a bug with the NI vi.  If you replace the Ni vi with the OpenG Search or Split String.vi, it will work correctly.
Kenny

0 Kudos
Message 12 of 38
(2,668 Views)
It's not a bug. The ^ character is a special character for the Match Pattern function. It indicates anchoring to the beginning of the string. If you replace it with ^\^ it will work.
0 Kudos
Message 13 of 38
(2,666 Views)

Thanks, Kenny K, I will use the Open G version.  I hope someone from NI sees this post and gets to work on it.

I wonder if this has to do somehow with NI's internal representation of strings or paths, or paths converted from strings.  Maybe internally a caret character is used to distinguish it as a string representing a path?

At least the Open G boys figured it out.

Thanks again!

0 Kudos
Message 14 of 38
(2,664 Views)
ahh, thank you for the info.  I would have never picked that up.
Kenny

0 Kudos
Message 15 of 38
(2,662 Views)
Oops. Typo. That's supposed to be just \^.

Also, you can replace the Search 1D array with just the Or Array Elements function.



Message Edited by smercurio_fc on 02-01-2008 01:21 PM
0 Kudos
Message 16 of 38
(2,666 Views)
Thanks to Kenny K and smercurio_fc for helping me out!  Regular expressions are tricky indeed.  I bet you can use one to figure out if you have a legal windows file name!  Then maybe you wouldn't have to pass in an autoindexed array of characters, but just one match pattern?  Might be a small improvement in execution time?
 
Thanks again for the help everyone!  Hopefully this post will be equally helpful to someone else in the future!
0 Kudos
Message 17 of 38
(2,659 Views)
You can. Like this:


I havent' thoroughly checked this for all cases, and I suspect one or more of those special characters would need to be "escaped". I'll leave that to you. Smiley Wink


Message Edited by smercurio_fc on 02-01-2008 01:32 PM
0 Kudos
Message 18 of 38
(2,653 Views)

Thanks, smercurio_fc!  While we're at it, I think this is on topic.  Aren't the only illegal characters for a filename ? < > | : / \ * "  I think it's only those nine characters.  So, if you're input box is only taking in a file name, without path info, I think you could only check for those nine characters.  I could be wrong.  Maybe a Windows expert is lurking around the forums?

You don't need to reply if I have this right, but please do if I have this wrong.  I believe you've created a character set inside those sqaure brackets [ ] for your regular expression, and if any one of those characters is in the searched string, you'll get a number greater than zero for a return value.  I hope this explains it to someone reading this post who might not have heard of regular expressions.  They are pretty powerful and deserve a Google sometime.  And some characters are special, and need to be "escaped", with a forward slash "\".  Like \t means "tab".

Thanks again to all respondents!

0 Kudos
Message 19 of 38
(2,644 Views)
I just did a blind conversion of the array that Kenny had done to a single pattern string. I didn't give any thought to the actual characters that were being used and whether they might still be legal characters under Windows. You're probably right about the character set. Don't really know off the top of my head.

As for the string I created and why it's like that, it's documented in the LabVIEW Help for the Match Pattern function.
0 Kudos
Message 20 of 38
(2,636 Views)