Re: Parsing a string



All:

I am trying to parse the following line:

 -rwxr-xr-x    1 nhodge   nhodge    4724464 Oct 31 18:36 Shakira -
Laundry Service - 03 - Whenever, Wherever.mp3

I need to grab the first char (-, d, or l), the size, and the file
name.  I am trying to do this using g_strsplit et. al., but I can't
quite get it to work.  My primary problems:

* The variable number of spaces between the fields.

* The fact that the file name can also have spaces.

You'll probably need regex support in order to do this. I'd suggest you
use pcre. The regex would be something like:
(.)[a-z-]{10}[ \t]+([0-9]+)[ \t]+([^ \t])+[ \t]+([^ \t]+)[ \t]+([0-9]+)[
\t]+....(etc.)

The bracketed expressions can then be got after doing a pcre_exec as
back references.

Another option: Looks like you want to get file names in a directory. In
that case, why don't you simply use this (pseudo code - just shows the
UNIX API calls to make):
        opendir()
        while (NULL != readdir())
        {
                lstat(&s, name);
        }
        closedir()
This will get you all file names and their attributes like file type
(S_ISREG, S_ISDIR, etc.), file size, etc.

Hope this helps.

Rgds,
Biswa.


Any ideas?  Thanks.

Neil


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]