如果对文件名不需要做判断的话,直接用
system( "rm -f /目录全路径/* ");
否则:
The following sample program searches the current directory for each of the arguments supplied on the command line.
#include
#include
#include
#include
static void lookup(const char *arg)
{
DIR *dirp;
struct dirent *dp;
if ((dirp = opendir( ". ")) == NULL) {
perror( "couldn 't open '. ' ");
return;
}
do {
errno = 0;
if ((dp = readdir(dirp)) != NULL) {
if (strcmp(dp-> d_name, arg) != 0)
continue;
(void) printf( "found %s\n ", arg);
(void) closedir(dirp);
return;
}
} while (dp != NULL);
if (errno != 0)
perror( "error reading directory ");
else
(void) printf( "failed to find %s\n ", arg);
(void) closedir(dirp);
return;
}
int main(int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++)
lookup(argv[i]);
return (0);
}