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 * / > " : |).

Nevermind!

 

TDMS Open handles "/" in a filesystem agnostic manner, whereas O/C/R File is filesystem dependent so it requires "\" on Windows.

0 Kudos
Message 31 of 38
(2,954 Views)

I use a very simple and OS-independent method: create a temporary file with that name, if it succeeds then the file name is valid. Is it a bad idea?

 

0 Kudos
Message 32 of 38
(2,716 Views)

@Snamprogetti wrote:

I use a very simple and OS-independent method: create a temporary file with that name, if it succeeds then the file name is valid. Is it a bad idea?

 


I wouldn't call it a bad idea, but as I said there is a built in function like I mentioned.

 

vi.lib\Utility\libraryn.llb\Is Name Multiplatform.vi

 

Your method could be wasting time because it sounds like you will be making the file twice.

Message 33 of 38
(2,700 Views)

That built-in function is a bit complicated, especially if you only need to check on current OS, yet it doesn't get every possible problem. It doesn't check maximum name length for example, and there may be other cases they didn't think of.

 

Testing is safer, and i'm not making the file twice, at least not now; if i wanted to create the real file right after the check, i wouldn't do the check... i'd just create it and handle errors

 

0 Kudos
Message 34 of 38
(2,697 Views)

That's now how I interpreted your post.

 


create a temporary file with that name


 

To me that sounds like you are making a file in something like %temp%\Example File Name.ini 

 

Then if it succeeds you know the file name is valid, and would then make that file in the correct location that you originally wanted like C:\Program Data\My Program\Example File Name.ini

 

In this case you wouldn't be properly checking for the character size limit either.

 

Also using the VI I mentioned it will provide a valid file name that will work.  So if you tried to make your file and it failed how would you handle it?  If you use the function I linked you won't need to worry about it because you know the file name it returns is valid.  Sure you have the 255 character limit (in Windows) to worry about but you at least have a good name to use.

0 Kudos
Message 35 of 38
(2,682 Views)

9 years later...but this was the first thing that showed up in a google search.

 

"Is Name Multiplatform" doesn't actually catch everything.  One failure case: trailing spaces on Windows.  Or even a file name that's only spaces.  Windows won't allow this, but "Is Name Multiplatform" won't object.

0 Kudos
Message 36 of 38
(792 Views)

Hi,

 

long time ago I had to prevent users from using illegal chars in filenames when they were ask to input a filename. That's what I used:

Use case: inside of a ValueChange event of the filename string input (string control set to update while typing)…

 

Best regards,
GerdW


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