简体   繁体   中英

Clear directory in standard C++ (cross-platform)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM