Skip to content

Instantly share code, notes, and snippets.

@nhatzHK
Created February 21, 2018 23:06
Show Gist options
  • Save nhatzHK/da7d2f1978a9d57ed9d460b898b66977 to your computer and use it in GitHub Desktop.
Save nhatzHK/da7d2f1978a9d57ed9d460b898b66977 to your computer and use it in GitHub Desktop.
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <ftw.h>
static int rmFiles(const char *pathname, const struct stat *sbuf, int type, struct FTW *ftwb)
{
if(remove(pathname) < 0)
{
perror("ERROR: remove");
return -1;
}
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr,"usage: %s path\n",argv[0]);
exit(1);
}
if (nftw(argv[1], rmFiles,10, FTW_DEPTH|FTW_MOUNT|FTW_PHYS) < 0)
{
perror("ERROR: ntfw");
exit(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment