[aclug-L] Re: Mp3Lister.app
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
gLaNDix wrote:
>
> ok, thanks... i'll take a look at this!
>
> jesse
The opendir/readdir version of the code looks something like this:
#include <sys/types.h>
#include <dirent.h>
#include <limits.h>
#include <string.h>
char *directory_name;
DIR *dir_structp;
struct dirent *dir_entp;
char path_buf[PATH_MAX];
if ((dir_structp = opendir(directory_name)) == 0) {
/* complain and exit or die */
}
while (dir_entp = readdir(dir_structp)) {
char *p;
if (p = (strrchr(dir_entp->d_name, '.')) {
if (!strcmp(p, ".mp3x")) {
sprintf(path_buf, "%s/%s", directory_name, dir_entp->d_name);
/* use pathname in path_buf has needed */
}
}
}
closedir(dirp);
This, of course, has a slight performance advantage over forking a shell and
running /bin/ls under popen(3). The other thing you get is complete control
over error messages -- ls will write to stderr if the requested directory
does not exist, and you have no control over that (other than to throw a
"2>/dev/null" into the popen command line).
One possibly nice thing that you get from using ls is that the output will
be sorted. Sorting requires that you buffer the pathnames until you get all
of them. This adds a bit of complexity, but if you're buffering them anyway,
sorting is just a qsort(3) call.
--
/*
* Tom Hull -- mailto:thull@xxxxxxxxxxx or thull@xxxxxxxxxx
* http://www.ocston.org/~thull/
*/
- [aclug-L] Re: Mp3Lister.app, (continued)
- [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
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/22
- [aclug-L] Re: Mp3Lister.app, Tom Hull, 1999/09/23
- [aclug-L] Re: Mp3Lister.app, Tom Hull, 1999/09/22
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/22
- [aclug-L] Re: Mp3Lister.app, Tom Hull, 1999/09/21
- [aclug-L] Re: Mp3Lister.app, gLaNDix, 1999/09/20
- [aclug-L] Re: Mp3Lister.app,
Tom Hull <=
|
|