We can delete non-empty directory using ftw using FTW_DEPTH. But I want to delete content of directory but not directory itself some thing similar to rm -rf dir/*.
How to achieve this using nftp/ftw ?
You can try this (WARNING, no confirm are required) :
#include <stdio.h> #include <ftw.h> #include <iostream> using namespace std; int list(const char *name, const struct stat *status, int type); int main(int argc, char *argv[]) { ftw(argv[1], list, 1); return 0; } int list(const char *name, const struct stat *status, int type) { if(type != FTW_D) { cout << "Deleting " << name << endl; remove( name ); } return 0; }
And call your app :
./main path_to_delete
You can try this (WARNING, no confirm are required) :
And call your app :