--- trunk/src/misc.c 2009/08/24 19:21:46 76 +++ trunk/src/misc.c 2009/08/25 12:49:03 77 @@ -21,6 +21,9 @@ #include #include +#include +#include + #include "gpxview.h" char strlastchr(char *str) { @@ -385,3 +388,27 @@ } #endif #endif + +/* recursively remove an entire file system */ +void rmdir_recursive(char *path) { + GDir *dir = g_dir_open(path, 0, NULL); + if(dir) { + const char *name = g_dir_read_name(dir); + while(name) { + char *fullname = g_strdup_printf("%s/%s", path, name); + // printf("deleting %s\n", fullname); + + if(g_file_test(fullname, G_FILE_TEST_IS_DIR)) + rmdir_recursive(fullname); + else if(g_file_test(fullname, G_FILE_TEST_IS_REGULAR)) + g_remove(fullname); + + g_free(fullname); + name = g_dir_read_name(dir); + } + + g_dir_close(dir); + } + g_rmdir(path); +} +