01-03-2025 02:06 PM
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?
I hate C.
01-03-2025 03:23 PM - edited 01-03-2025 03:24 PM
"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:
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".)
01-04-2025 12:12 AM
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.
01-04-2025 09:28 AM
@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.
01-04-2025 01:39 PM
The file came from my camera, not LabVIEW.
I ended up doing this:
01-06-2025 10:55 AM
@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.