File Type (Binary or ASCII) 
Author Message
 File Type (Binary or ASCII)

Hi All (again)

Is There a Way to know witch type is a file???  (Binary or ASCII)

for example:

file.jpg    (is binary)

file.htm (is ACII)

how can i do this??

Thanks ALL

Fbio



Mon, 25 Jul 2005 21:35:51 GMT  
 File Type (Binary or ASCII)
Select Case myext

    Case "exe"

    Case 'jpg"

    Case "etc,etc,etc"

End Select

.


Quote:
> Hi All (again)

> Is There a Way to know witch type is a file???  (Binary or ASCII)

> for example:

> file.jpg    (is binary)

> file.htm (is ACII)

> how can i do this??

> Thanks ALL

> Fbio



Mon, 25 Jul 2005 22:35:21 GMT  
 File Type (Binary or ASCII)
This is a Workaround, because i need to test al file extensions or use the
CASE ELSE  !!!

do you agree???



Quote:
> Select Case myext

>     Case "exe"

>     Case 'jpg"

>     Case "etc,etc,etc"

> End Select

> .



> > Hi All (again)

> > Is There a Way to know witch type is a file???  (Binary or ASCII)

> > for example:

> > file.jpg    (is binary)

> > file.htm (is ACII)

> > how can i do this??

> > Thanks ALL

> > Fbio



Tue, 26 Jul 2005 01:17:15 GMT  
 File Type (Binary or ASCII)
how can i know if a part of the file is ACII or Binary????
Quote:

> It is possible to read the first few bytes of a file, then see if the
> characters fall within the ascii realm.  Most of this is built into the
> vb.net, and is accessed via classes.

> Cade


> > Hi All (again)

> > Is There a Way to know witch type is a file???  (Binary or ASCII)

> > for example:

> > file.jpg    (is binary)

> > file.htm (is ACII)

> > how can i do this??

> > Thanks ALL

> > Fbio



Tue, 26 Jul 2005 01:20:00 GMT  
 File Type (Binary or ASCII)

Quote:
> Hi All (again)

> Is There a Way to know witch type is a file???  (Binary or ASCII)

> for example:

> file.jpg    (is binary)

> file.htm (is ACII)

> how can i do this??

> Thanks ALL

> Fbio

All files are binary.  Whether the data they contain represents text or not
doesn't change that.  

If you need to distinguish between a human readable (i.e. text) and machine
readable (i.e. binary), then you can do as Cade suggested and read bytes
from the file and if they fall in the ASCII range of 32 to 126, then you
could probably assume that it's a text file (taking into account that there
will probably be ASCII 13, ASCII 10, or ASCII 9 characters (CR, LF, and
TAB).  If on the other hand you encounter characters outside that ASCII
range, then you've probably got a binary file.  This method may not be 100%
effective, however.  You may encounter files that are human readable but
still have a few "binary" characters.  

You might try using a tolerance value.  If x% of the characters in the file
fall in the ASCII Range 32 to 126, then it's human readable otherwise not.

HTH

Chris

--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail



Tue, 26 Jul 2005 03:55:52 GMT  
 File Type (Binary or ASCII)

Quote:

> Never thought about reading all the file, then deciding if it is human
> readable by the percentage that was human readable.  Not a bad idea.

> As another thought, you could search the file for common words ->
>    A, An, the, Me, I, etc.....

This gets further into a definition problem: what is meant by ASCII, and/or
why does your program want to know? Not all files that contain only
ASCII-defined characters are human readable.

Several compression techniques create datastreams that contain only ASCII
characters, but it isn't human readable. And, does it matter if the
uncompressed file would be ASCII or binary?

A .csv file is human readable (if you know the application), but may not
contain any words.

I get spam every day that's human readable, but not to _this_ human - I only
recognize English and a little French. And speaking of localization, lots of
characters > 127 are used in some languages.

Want to handle DBCS? Unicode?

So, it depends on why the program needs to know. What works for one purpose
may not work for others. Checking the file extension isn't at all
fool-proof, but may be a better indication of the purpose of the file unless
you do a lot of checking on the whole file. And, much less overhead if you
don't have to open the file.

Just my 2[cents - no ASCII cent sign!]

-jcf



Wed, 27 Jul 2005 02:05:40 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. INET and transfer type ascii vs. binary

2. Open Binary file as Ascii

3. Write non-ASCII chars into binary file

4. File conversion - Binary to ASCII

5. Is file ASCII or WinWord (or other binary) ?

6. Searching ASCII in a binary file ?

7. Inet control file transfer mode (binary/ascii)

8. How I send a binary/ascii file using winsock

9. How to write non-ASCII chars into a binary file

10. Help! User Defined Type and ASCII file reads

11. binary files and user defined data types

12. Storing user types in a binary file?

 

 
Powered by phpBB® Forum Software