From: Daniel DeLorme Date: 2007-06-20T08:22:51+09:00 Subject: Re: Check for text file Nobuyoshi Nakada wrote: > You can use String#count: > > def File.binary?(path) > s = read(path, 4096) and > !s.empty? and > (/\0/n =~ s or s.count("\t\n -~").to_f/s.size<=0.7) > end > > In any case, it doesn't work for non-ascii files. Pedantic correction: it desn't work for non-western scripts. French uses accents here and there but it would pass the test above. Still, I have to say I was surprised; I didn't know that a hyphen in String#count had the same effect as in a regexp character class. Talk about an undocumented feature! Daniel