[aclug-L] Re: Mp3Lister.app
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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;
cnt++;
/* do something with your file name in name_buf */
}
pclose(f);
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 Mp3Lister.app 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
* http://www.ocston.org/~thull/
*/
- [aclug-L] suggestion, Michael Holmes, 1999/09/19
- [aclug-L] Mp3Lister.app, gLaNDix, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, John Phillips, 1999/09/20
- [aclug-L] Re: Mp3Lister.app,
Tom Hull <=
- [aclug-L] Re: Mp3Lister.app, Jeff, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, Carl D Cravens, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, Tom Hull, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, Carl D Cravens, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/20
- [aclug-L] Re: Mp3Lister.app, Clint A. Brubakken, 1999/09/21
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/22
- [aclug-L] Re: Mp3Lister.app, Clint A. Brubakken, 1999/09/22
|
|