Determine text file or Binary file
-
I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN
You can open the file, read the contents, and examine the bytes to determine if the file contains any binary data. You can see if the characters are in the normal text range, as well as checking for CR/LF characters. onwards and upwards...
-
I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN
A file is only "text" or "binary" in the context of the application that created it. Historically speaking, if the file contained non-printable characters, it was considered binary. Otherwise, it was considered text. What exactly is it that you are trying to do?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN
I don't think so. This wouldn't make any sense to me. After all, a binary file appears as garbage in a text editor because the bytes will not map to ascii to form any kind of intelligible sentence in any language. The text editor doesn't care if the file you tell it to open is binary or not. It will just read the file and try to map the bytes into ascii and display whatever random characters the data happens to map to. If there were an automatic function for doing this, the people that wrote notepad and wordpad probably would have popped up an warning message reading, "warning, processing binary file"; or something like that. All files are binary files, in my mind. It just so happens that a text file is a special kind of binary file where each byte maps to an appropriate ascii symbol to form intelligible letters/numbers/symbols. Even the carriage returns and line feeds are simply bytes of data that map to the appropriate ascii symbol. I think writing an algorithm to guess if something is good enough to be a text file would be awfully difficult if not impossible. You'd have to read each byte in and make a lot of assumptions about the data.