From: Austin Ziegler Date: 2003-04-19T11:16:30+09:00 Subject: Re: How to test for text file On Sat, 19 Apr 2003 01:14:08 +0900, Peter B. Ensch wrote: > Yukihiro Matsumoto wrote: >>| In perl, -T returns true if is a text file and -B >>| returns true if is binary. >> You have to define what is text file first. Traditional Perl test >> does not work for Japanese text (nor Unicode text). > Ah! Not having worked with Unicode before, I had not considered > this. Does your answer assume that I need to define 'text file' > and then open/read the file to see if it meets the definition? In > other words, it is not possible to do something like: > > if text file > open and process > else > do not open > end > > BTW, thanks for answering my question, Matz, and thanks for ruby. > I'm having a lot of fun learning it. You could use MIME::Types [RAA:mime-types], which does a decent job of MIME Content-Type analysis, and it knows most extensions for filee types. I may port File::MMagic from Perl to do this sort of thing, though. -austin -- Austin Ziegler, austin@halostatue.ca on 2003.04.18 at 22:09:30