Here is a quick hack.
You would need to call stat() for your files to be safe
and check the value using the macros S_ISDIR and S_ISREG
so you can implement further (?recursive?)subdirectory removal.
Needless to say error checking is all up to you.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#define errstring "UNHELPFUL USER ERROR MESSAGE"
int rmfile(char *name);
char *basename(char *name);
int main(int argc, char **argv) {
DIR *mydir;
char buf[100], *pptr;
struct dirent *entry;
pptr = basename(argv[1]);
if ( (mydir = opendir(argv[1])) != NULL) {
while ( (entry = readdir(mydir)) != NULL) {
printf("Looking at %s\n", entry->d_name);
sprintf(buf,"%s/%s",pptr,entry->d_name);
printf("Filename is %s operation returns %d,\n", buf, mfile(buf));
}
}
closedir(mydir);
return 0;
}
int rmfile(char *name) {
int x;
printf("Now unlinking name %s\n", name);
/* x = unlink(name);
return x;*/
}
char *basename(char *name) {
int i = 0, y;
char *tmp = name, *ret;
while (*name++) {
i++;
if (*name == '/') {
y = i;
}
}
if (y && (ret = malloc(sizeof name)) ) {
strncpy(ret,tmp,y);
return ret;
}
return errstring;
}