Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a folder in C++?

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?

like image 487
user88240 Avatar asked Apr 09 '09 15:04

user88240


People also ask

Why I cant delete a folder in C drive?

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.

How do I delete a folder from C drive program files?

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”.

How do I delete an existing folder?

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.

How do I delete a folder from my C drive in Windows 11?

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.


1 Answers

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)

like image 79
Edouard A. Avatar answered Sep 23 '22 22:09

Edouard A.