Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!mit-eddie!rutgers!att!ulysses!andante!alice!debra From: debra@alice.UUCP (Paul De Bra) Newsgroups: comp.unix.questions Subject: Re: Detecting type of file in a program Message-ID: <8868@alice.UUCP> Date: 5 Feb 89 00:04:15 GMT References: <192@henry.ece.utexas.edu> Reply-To: debra@alice.UUCP () Organization: AT&T, Bell Labs Lines: 17 In article <192@henry.ece.utexas.edu> po@volta.ece.utexas.edu () writes: >In my program, I am using opendir() to read in the names of >text files from a directory. >How can I tell whether a file is text or an object file ? >Is there a better way than using : > system("file filename > /tmp/tempfile") The only way is to look at the contents of the file, which is what the utility "file" does too. So read a number of bytes from the file, and then guess, depending on what you see. Paul. -- ------------------------------------------------------ |debra@research.att.com | uunet!research!debra | ------------------------------------------------------