2016-12-02 2 views

Antwort

1

Sie können diese versuchen (WARNING, sind nicht bestätigen erforderlich):

#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; 
} 

Und rufen Sie Ihre App:

./main path_to_delete

+0

Hallo Alban Dank für die Antwort, das gilt, wenn der Inhalt des Verzeichnisses nur normale Dateien sind. Ich suchte nach einem Fall, wo wir Verzeichnisse auch innerhalb des Hauptverzeichnisses haben können – Karna

+1

Ich fügte folgenden Code für das Löschen von regulären Dateien hinzu inline 'int helper_routine (const char * fpath, const struct stat * sb, int typeflag, struct FTW * ftwbuf) { if (! S_ISDIR (sb-> st_mode)) entferne (fpath); } zurückgeben 0; } ' – Karna

Verwandte Themen