Path: utzoo!attcan!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.questions Subject: Re: Detecting type of file in a program Message-ID: <944@philmds.UUCP> Date: 7 Feb 89 06:08:23 GMT References: <192@henry.ece.utexas.edu> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 18 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") Since Unix does not have the notion of a file type (at least not like V..) you'll end up doing something equivalent to what 'file' does. Using file perhaps enhances portability. Try as a variant: pp = popen("exec file filename","r"); to get the lines of 'file' into your program (and use 'pclose', not 'fclose' to close the stream). You can even grep for 'text' in the output from file. Leo.