Complete.Org: Mailing Lists: Archives: discussion: September 1999:
[aclug-L] Re:

[aclug-L] Re:

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: aclug-L@xxxxxxxxxxxx
Subject: [aclug-L] Re:
From: Tom Hull <thull@xxxxxxxxxxx>
Date: Mon, 20 Sep 1999 13:08:00 -0500
Reply-to: aclug-L@xxxxxxxxxxxx

A first approximation would be something like:

    #include <limits.h>
    #include <stdio.h>

    char cmd_buf[PATH_MAX + 16], name_buf[PATH_MAX];
    char *directory_name;
    FILE *f;
    int cnt = 0;

    sprintf(cmd_buf, "/bin/ls %s/*.mp3z", directory_name);
    if ((f = popen(cmd_buf, "r") == 0) {
        /* complain and die or exit */
    while (fgets(name_buf, sizeof name_buf, f)) {
        char *p;
        if (p = strchr(name_buf, '\n'))
            *p = 0;
        /* do something with your file name in name_buf */
    if (cnt == 0) {
        /* you might want to tell someone that there are no .mp3z files
         * in the specified directory. */

Instead of running popen(3), you could implement your own directory search
using #include <dirent.h>, but you would basically be re-implementing a
special-purpose ls(1). You can check the source code to ls(1) to find out
how it works, or just grep for diropen(, since all such uses are pretty
much the same cookie-cutter code.

gLaNDix wrote:
> hey, does anyone have a simple C prog that lists mp3z in an arbitrary
> directory, and puts the list into a file?  I'm wanting to create a program
> called that uses the WINGs interface that will list mp3z in a
> user-specified directory, save the user-defined file in another user-defined
> directory, and add user-defined account info (e-mail, name, ICQ,etc) as a
> header to the lists.  However, I'm not the greatest programmer in the world,
> and need something simple to start my program with...  i will of course give
> credit where credit is due!
> if you can help me out, e-mail me the source!
> thanks,
> jesse

No credit needed. Also, note that the above code is just off the top of
my head for illustration purposes only. It hasn't been compiled, and
probably doesn't work, but it should point you in the right direction.

 * Tom Hull -- mailto:thull@xxxxxxxxxxx or thull@xxxxxxxxxx

[Prev in Thread] Current Thread [Next in Thread]