void remove_all ( const fs::path &dir_path) { if (fs:: exists (dir_path)) { for ( const auto &entry : fs:: directory_iterator (dir_path)) { if (fs:: is_directory (entry. path ())) { remove_all (entry. path ()); } else { fs:: remove (entry. path ()); fs:: remove (dir_path); int main () { fs::path dir_path = "./test_dir" ; remove_all (dir_path); return 0 ;

该代码实现了删除文件夹底下所有文件的功能。

  •