问题描述:

My goal is simple: I'd like a to clear a directory (delete all of the sub-directories and files it contains, but not delete the directory itself) given a path, in a cross-platform way.

Most of the solutions I've found online either involve using dirent.h which, from my understanding, is non-standard and may not work on non-POSIX systems (notably Windows) or using Boost.Filesystem. However, building Boost and including it in my project is a lot to ask for if all I'd like to do is clear a directory.

Is there a way to achieve my goal in standard C++? Or, has the standard not advanced to this point yet?

网友答案:

A filesystems library was "added" to C++ in the "Filesystems TS", so you may be able to find an experimental implementation in your compiler's standard library implementation.

However, it's not yet part of any formal standard. My understanding is that it'll be part of C++17.

Until then, Boost it is — or your own hand-crafted code on systems that are neither Windows nor POSIX-compliant.

相关阅读:
Top