Create a disk usage counter
This is a simple utility that totals the size of every file in a directory and its sub-directories. It runs on both POSIX/Unix and Windows file systems.
How to do it…
This recipe is a utility to report the size of every file in a directory and its sub-directories, along with a total. We'll re-use some of the functions we've used elsewhere in this chapter:
- We start with a few convenience aliases:namespace fs = std::filesystem; using dit = fs::directory_iterator; using de = fs::directory_entry; 
- We also use our formatspecialization forfs::pathobjects:template<> struct std::formatter<fs::path>: std::formatter<std::string> { Â Â Â Â template<typename FormatContext> Â Â Â Â auto format(const fs::path& p, FormatContext& ctx) { Â Â Â Â Â Â Â Â return format_to(ctx.out(), "{}", p.string()); Â Â Â Â } };...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                