-
January 18th, 2005, 02:33 AM
#1
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
-
January 18th, 2005, 03:07 AM
#2
Re: Determine text file or Binary file
There is nothing like that, because everything is binary. Even the text files are binary, it's just that the binary numbers are ASCII (or UNICODE) codes.
See this FAQ for more.
-
January 18th, 2005, 04:36 AM
#3
Re: Determine text file or Binary file
It's not an absolute guarantee (and this would only be valid for files originated under DOS or Windows) but you could try parsing the file for each occurrence of the character 0x0D. If every occurence is followed by the character 0x0A, then it's probably a text file.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
January 18th, 2005, 04:42 AM
#4
Re: Determine text file or Binary file
You might also want to search the file for non-alphanumeric characters, like 0x00 ... 0x08 or 0x0E ... 0x1F because chances are really small such characters appear in text files, but chances are very high that such characters appear in binary files.
-
January 18th, 2005, 06:03 AM
#5
Re: Determine text file or Binary file
Take a magnifier, remove the HDD cover, and see if the file inside is readable.
Well, this is not first time discussed problem/quiz/homework.
Because a "text file" is generally intended to show sometimes sometext somewhere, just open it with a text viewer/editor (notepad is a good and free one ) or display it in your application in an edit control and see what's inside. Nobody can assure you that a flat (text) file always contain only printable characters plus CR/(LF)s and tabs.
IMHO: from practical point of view, to see if an unknown (type or what is intended for) file is a "text" file or not it's not relevant.
The situation can change for file types those have format specifications, for an example it's possible to be necessary to decide if a file is a TIFF, GIF, JPEG, or simply garbage.
Originally Posted by mjvalan
(file name doesn't have file extension).
Never trust in file extension. It can be changed anytime as well.
-
January 18th, 2005, 06:28 AM
#6
Re: Determine text file or Binary file
Originally Posted by mjvalan
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
As others have mentioned, there is no way to guarantee that a file is "text" or "binary", since all files are binary. That's like asking whether an animal is a dog or poodle.
Look at how most GUI-based FTP programs work. They usually have lists of file name extensions where it is assumed that these files are text files. You have the option in these programs of changing these assumptions when neccessary.
Regards,
Paul McKenzie
-
January 19th, 2005, 12:42 AM
#7
Re: Determine text file or Binary file
Thank you for your replies.
Regards
MJVALAN
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|