How to delete a directory and its contents in (POSIX) C? [duplicate]
问题 This question already has answers here : Removing a non empty directory programmatically in C or C++ (9 answers) Closed 2 years ago . I am most interested in the non-recursive case, but I am guessing others who might track this question would prefer seeing the recursive case. Basically, we are aiming to accomplish: rm -rf <target> However, a system call would be an immature answer. 回答1: You need to use nftw() (or possibly ftw()) to traverse the hierarchy. You need to use unlink() to remove