How to find out if a file is a binary file or not

How to find out if a file is a binary file or not

Post by Jerr » Sat, 31 Mar 2001 15:40:58



Hi, I was wondering if there was any way other than using the file command
in Unix, to find out if a file was a binary file or not.  Any other command
or series of commands, or system calls or library functions would be a great
help.  Thanks guys!

Jerry

 
 
 

How to find out if a file is a binary file or not

Post by Christoph Hintermülle » Sat, 31 Mar 2001 16:28:54


Hi
That depends wether the userrights are set correctly for that file or not :)
because when using
   stat
you only get to know what major type the file belongs to
and the acess rights

if you want to be sure to have an binary file, there is AFAIK no way than
open the file, check some of the first bytes and decide uppon them :(
cu
Christoph


> Hi, I was wondering if there was any way other than using the file command
> in Unix, to find out if a file was a binary file or not.  Any other command
> or series of commands, or system calls or library functions would be a great
> help.  Thanks guys!

> Jerry

--
THESIS:     God is alive
PROOVE:     Who else would have scheduled the mankind and world first
             recommendation of resrearch????
CONCLUSION: Scientists do what he wants, willing or not:)

 
 
 

How to find out if a file is a binary file or not

Post by David Schwart » Sat, 31 Mar 2001 16:56:24



> Hi, I was wondering if there was any way other than using the file command
> in Unix, to find out if a file was a binary file or not.  Any other command
> or series of commands, or system calls or library functions would be a great
> help.  Thanks guys!

        What's your definition of a "binary file". That'll give you your
answer.

        DS

 
 
 

How to find out if a file is a binary file or not

Post by cLIeNUX us » Sat, 31 Mar 2001 17:14:54



Quote:>Hi, I was wondering if there was any way other than using the file command
>in Unix, to find out if a file was a binary file or not.  Any other command
>or series of commands, or system calls or library functions would be a great
>help.  Thanks guys!

>Jerry

First you have to define "a binary". All computer files are binary.

Rick Hohensee
www.clienux.com

 
 
 

How to find out if a file is a binary file or not

Post by Donald McLachl » Sat, 31 Mar 2001 21:43:02


At the risk of doing someones assignment ...

while((c = getchar()) != EOF)
{
        if(!isascii(c))
                return(0);

Quote:}

return(1);

Now the executable can be used (and the return value checked) from shell
scripts to test files.  If isascii() does not map to the set of chars you
need, then build a truth table that does.

--

Communications Research Centre / RNS    Tel     (613) 998-2845
3701 Carling Ave.,                      Fax     (613) 998-9648
Ottawa, Ontario
K2H 8S2
Canada

 
 
 

How to find out if a file is a binary file or not

Post by John Gord » Sat, 31 Mar 2001 23:56:00



> Hi, I was wondering if there was any way other than using the file command
> in Unix, to find out if a file was a binary file or not.  Any other command
> or series of commands, or system calls or library functions would be a great
> help.  Thanks guys!

you could do an "od -c" on the file, and have a look at the output.  if
there are any occurrences of numbers above, say, 200, then it's a binary
file.

---
"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang, rec.games.board


 
 
 

How to find out if a file is a binary file or not

Post by Mark Ra » Sun, 01 Apr 2001 05:12:11



>Hi, I was wondering if there was any way other than using the file command
>in Unix, to find out if a file was a binary file or not.

All files are binary.  Unix doesn't make the distinction that some so-called
OSes do.  Do you mean "has no high bits set", "contains no bytes for which
isprint() returns false", or some such?  If so, it's pretty easy to code up a
test for it.

Quote:>Any other command or series of commands, or system calls or library
>functions would be a great help.

Explain exactly what you need to know, and we might be able to come up with
tests.  I suspect file(1) is going to be the best choice in many cases.
--