如何删除C ++中的非空目录? [英] How to remove a non-empty directory in C++?
问题描述
rmdir
,但它只会删除非空目录,所以如何列出并删除所有包含的文件? 我知道使用Boost文件系统并不困难,但我希望避免构建并依赖于这个小任务... 是的,你通常必须先删除内容。如果你不想使用Boost,那么你很难用非可移植的代码来查找所有的文件(例如, FindFirstFile
,<$ c在Windows上是$ c> FindNextFile ,在Unix上是 opendir
, readdir
并删除所有这些。
In C++, how can I remove a directory with all its contained files? I know there is rmdir
, but it will only remove non-empty directories, so how do I list and remove all contained files first?
I know it shouldn't be hard using Boost Filesystem, but I kind of want to avoid building and depending on it just for this one little task ...
Yes, you normally have to remove the contents first. If you don't want to use Boost for this, you're pretty much stuck with writing non-portable code to find all the files (e.g., FindFirstFile
, FindNextFile
on Windows, opendir
, readdir
on Unix and similar) recursively, and remove all of them.
这篇关于如何删除C ++中的非空目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!