From: James Masters Date: 2009-09-22T00:35:21+09:00 Subject: Re: Determining if a file is binary or text On Sep 20, 2:17 am, Robert Klemme wrote: > I fully agree: the difficult part is in deciding: what is a text file? > If that has been clarified enough the algorithm for checking should > become much more obvious. I agree - this is what it comes down to. BTW, I tried the following on my project (using Find#find to get the tree) on the first 40 "lines" (which I know can theoretically be very short or long in a "binary" file) and it seems to work for what I'm doing. This works well for me also because I'm checking for the presence of a header and I can do this check along with checking for a header while the file is still open: line.match(/^[[:print:]\t\n\r]+$/) But probably a better approach would be to use a ratio of characters that are printable against those that may traditionally be non- printable in the even that some "non-printable" characters are present in a text file. This is what SVN does (found the link from a post from Xavier on a "ptools" website when I Googled it): http://subversion.tigris.org/faq.html#binary-files And it also appears to be what File#binary? is doing in ptools (I checked the source code; thanks Dan for the pointer).