How can I delete a folder using C++?
If no cross-platform way exists, then how to do it for the most-popular OSes - Windows, Linux, Mac, iOS, Android? Would a POSIX solution work for all of them?
Change permissions to be able to delete the folder. So, here you have to get a little confused. Right-click on the desired folder, go to "Properties", open the "Security" section and open the "Advanced" tab. Open the menu item "Owner" and select yourself from the list "Change owner to" and click OK.
Step 1. Press "Windows" + "E" in Windows 10 to open Windows Explorer. Step 2. Open C drive, locate the folders or files that you don't need anymore, right-click them and choose “Delete”.
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
To use this method, first, boot your Windows 10 or Windows 11 PC in safe mode using our guide. Once you're in safe mode, launch File Explorer and locate the folder to delete. Then, right-click this folder and choose “Delete.” Your folder is now deleted.
I strongly advise to use Boost.FileSystem.
http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/index.htm
In your case that would be
boost::filesystem::remove_all(yourPath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With