From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can labview Differentiate Between Text And Binary Files?

Solved!
Go to solution

I found a function to determine the file extension, but this solution is not effective because I have to write all possible extentions so that it can read it.

 

This is why I want to ask if there is another method to distinguish the binary file and the text file in labview?

Thank you.

   Sans titre.png

0 Kudos
Message 1 of 4
(3,136 Views)

Technically all files are binary ... so if you cannot rely on the extension you'll have to read and check the content.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 4
(3,103 Views)
Solution
Accepted by topic author imadouino

Have you ever used a "show all the characters" Text Editor and pointed it at an arbitrary file?  You (the Human Being) can quickly tell Binary from Text because you see ... "text", meaning letters/numbers separated by spaces and broken into lines of "reasonable" length, while "Binary" files look like gibberish and lack line structure.

 

[Actually, as Yamaeda pointed out, all files are Binary, and a "Text" file written using Kanji characters might look pretty unrecognizable, too ...]

 

If I wanted to write a function that would "make a good guess" if the file was primarily ASCII Text, I'd read 1000 characters (or, perhaps, the entire file) and ask the following:

  • Are all of the characters 7-bit bytes, i.e. as U8 values, are all <128?
  • Are 10% (or so) of the characters the ASCII Space (0x20) character?
  • Are some form of <NL> (such as ASCII <CR>, 0x0d or ASCII<LF>, 0x0a) about 1% of the characters?

If the answer to all was "Yes", I'd say "Almost surely Text" (though I should probably analyze the entire file).  Note that a LabVIEW Delimited Spreadsheet File might not have any embedded spaces, so Criterion 2, above, might be "weak" ...

 

Bob Schor

Message 3 of 4
(3,087 Views)

You might also be able to do something using MIME content types and check the file for any of the standard headers, but that can be slow and cumbersome, and will only catch binary data files with a known header type.

Jon D
Certified LabVIEW Developer.
0 Kudos
Message 4 of 4
(3,056 Views)