[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Determining if a file is text or binary via the KDE API
From:       Andras Mantia <amantia () freemail ! hu>
Date:       2003-02-27 15:55:39
[Download RAW message or body]

On 2003. February 27., Thursday 16:41, Frans Englich wrote:
> Hi all,
>
> For a script utility I'm writing I need to determine whether a file is
> pure text or binary. I've had a look at the 'file' utility but it's
> output is inconsistent and it just doesn't work 100% correct. This my
> solution right now.
>
> But, I came to think of that some parts of the KDE API is exported to
> shell scripts(I read somewhere). Perhaps there's a method to determine
> text/binary via the KDE API in some way?

There was a thread this week related to this issue. With KDE 3.2 it will be 
possible with the help of KMimeType::findFormatByFileContent(const QString&) 
method. I use:
   bool text = false;
   KMimeType::Format f = KMimeType::findFormatByFileContent(url.path());
   if (f.text && f.compression == KMimeType::Format::NoCompression)
       text = true;

If you want this in the upcoming KDE 3.1.1,  "backport" that method locally 
for your application. I'm afraid there is no easy way for KDE 3.1 or earlier 
versions.

If you would like to detect only shell scripts, you may use the other 
KMimeType methods and check for application/x-shellscript.

Andras
-- 
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic