1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
/*
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
Copyright (C) 2005- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#include "clean_dir.h"
#include "stringtools.h"
#include <dirent.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
int clean_dir(const char *dirname, const char *delete_pattern)
{
char subdir[PATH_MAX];
struct dirent *d;
DIR *dir;
dir = opendir(dirname);
if(!dir)
return 0;
while((d = readdir(dir))) {
if(!strcmp(d->d_name, "."))
continue;
if(!strcmp(d->d_name, ".."))
continue;
sprintf(subdir, "%s/%s", dirname, d->d_name);
clean_dir(subdir, delete_pattern);
if(string_match(delete_pattern, d->d_name)) {
unlink(d->d_name);
}
}
closedir(dir);
return 1;
}
/* vim: set noexpandtab tabstop=4: */
|