Notes:
- The main function is to traverse the path. If you know how to traverse the path, you can delete it.
- At that time, the macro definition of the file type was not found, so I had to traverse the output type first. Note that in Linux, the path is considered as a special file. 8 is a common file, 4 is a path, and 4 is the type of "." and "...". Make a difference.
Void remove_dir (char * sz_dir)
{
Char subname [256];
Dir * pdir = NULL;
Struct dirent * pdirent = NULL;
Pdir = opendir (sz_dir );
If (pdir ){
// Printf ("into dir % s/n", sz_dir );
While (pdirent = readdir (pdir ))! = NULL ){
// Printf ("type is % d/N", pdirent-> d_type );
// Printf ("name is % s/n", pdirent-> d_name );
If (pdirent-> d_type = 8 ){
Sprintf (subname, "% S/% s", sz_dir, pdirent-> d_name );
Remove (subname );
}
If (pdirent-> d_type = 4
& Strcmp (pdirent-> d_name ,".")! = 0
& Strcmp (pdirent-> d_name ,"..")! = 0 ){
Sprintf (subname, "% S/% s", sz_dir, pdirent-> d_name );
Remove_dir (subname );
}
}
Closedir (pdir );
Remove (sz_dir );
}
Else {
Printf ("error in reading % s: % s/n", sz_dir, strerror (errno ));
}
}