- You need to use nftw() (or possibly ftw()) to traverse the hierarchy.
- You need to use unlink() to remove files and other non-directories.
- You need to use rmdir() to remove (empty) directories.
You would be better off using nftw() (rather than ftw()) since it gives you controls such as FTW_DEPTH to ensure that all files under a directory are visited before the directory itself is visited.