views:

128

answers:

2

how to remove a entire directory in c++

+2  A: 

See this code snippet.

plinth
That's Windows only though. You might as well just use `system("rmdir folder_name");`
Peter Alexander
The question is tagged visual-studio-2005 and windows.
plinth
The `windows` tag was added by someone else, maybe the OP is developing on VS but wants to stay multiplatform
Manuel
Ah, I see and apologize. I still think portability should be maintained, even if not entirely necessary, providing it doesn't come at great expense.
Peter Alexander
+11  A: 

There isn't a standard way of manipulating the filesystem in C++, so you will have to use system specific code or use a wrapper around it. For example, Boost.Filesystem.

As you indicated you are using Windows you could use the Win32 API however it is a a C API rather than a C++ API which means it is slightly more complex to use from C++. As it is Windows specific it won't work on other operating systems. In my opinion the API is not as well designed as Boost.Filesystem.

Yacoby
+1 Boost.Filesystem is a beautiful DSL for filesystem operations, and your code will be portable. Definitely go for it.
just somebody