Home > Net >  How to delete all files in a certain folder
How to delete all files in a certain folder

Time:09-23

I'm trying to make a feature in my program to delete all files in the Windows temporary folder "(C:\Users\Owner\AppData\Local\Temp)", how would I do this?

CodePudding user response:

Call the Win32 API GetTempPath() function to get the user's %TEMP% folder path, then you can either:

If you want a pure C solution, and are using C 17 or later, then you can use std::filesystem::temp_directory_path(), using std::filesystem::directory_iterator and std::filesystem::remove() in a loop, or just std::filesystem::remove_all() by itself.

  • Related