LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get File Extension

The function "Get File Extension" sometimes returns the file extension with a trailing null.

And the function "Trim Whitespace" won't remove the trailing null.

Whyyyyyyyyy?

 

paul_a_cardinale_0-1735934759327.png

 

I hate C.

0 Kudos
Message 1 of 6
(213 Views)

"Get File Extension" just does some string parsing on the filename, so either the filename does have a null at the end, or the Refnum to Path function is sticking an extra null in there.

 

I tried using LabVIEW to create a file with a null at the end of the name. As far as I can tell, Windows will create the file, but will strip the null out. However- LabVIEW will retain the null in the filename within the refnum:

 

Example_VI.png

 

If you're creating the file in LabVIEW, is it possible it's creating the filename with a null in it? If so, LabVIEW will "remember" that.

 

(Also, the documentation for "Trim Whitespace" explicitly says what it removes (ASCII whitespace characters, spaces/tabs/newlines/linefeeds). I would've been surprised if it removed a null, which is a control character not a whitespace character. To be pedantic, the function is "trim whitespace" not "trim non-printable-characters".)

Message 2 of 6
(185 Views)

BertMcMahan answered why trim whitespace doesn't strip null. You didn't ask, but if you were still looking for a way to trim the null a quick way is to use the Search and Replace String function with the replacement left unwired. I'm guessing this isn't super performant, but you probably aren't trimming a million file names in a time critical loop.

 

Lavezza_0-1735971168934.png

 

Message 3 of 6
(149 Views)

@BertMcMahan wrote:

I tried using LabVIEW to create a file with a null at the end of the name. As far as I can tell, Windows will create the file, but will strip the null out. However- LabVIEW will retain the null in the filename within the refnum:

 

If you're creating the file in LabVIEW, is it possible it's creating the filename with a null in it? If so, LabVIEW will "remember" that.


Played around with @BertMcMahan example; surprisingly it is not LabVIEW 2019, but 2023 or something like that. Don't have LabVIEW on this computer to test. You can put a file close after the file write function and get the same result, a null character at the end.  

 

The file path is just an "in and out" operation. The file functions do not do check for valid names, they only will give an error if there is something wrong when trying to apply the function. So whatever you put in, is what you get out. It appears that Windows automatically fixes the null character error but does not report anything to LabVIEW thus no error in the function.

 

FYI: OpenG has a remove Whitespace function that includes non-printable characters.

Message 4 of 6
(115 Views)

The file came from my camera, not LabVIEW.

I ended up doing this:

paul_a_cardinale_0-1736019506924.png

 

0 Kudos
Message 5 of 6
(102 Views)

@mcduff wrote:

 

Played around with @BertMcMahan example; surprisingly it is not LabVIEW 2019, but 2023 or something like that. Don't have LabVIEW on this computer to test.


Sorry about that, I used the LAVA Code Capture Tool that's supposed to downsave it to 2019 but I don't actually have 2019 installed to verify. Must be a glitch in the tool.

0 Kudos
Message 6 of 6
(56 Views)