lfilesystem  0.0.1
C++ filesystem library
files_dir_enumerate.cpp

This code reads all the files in the current working directory, prints them line by line, concatenates all the output and prints the combined data to a new file.

See also
files::Directory
/*
* ======================================================================================
* __ ____ __ __ ____ ___
* ( ) (_ _)( \/ )( ___)/ __)
* )(__ _)(_ ) ( )__) \__ \
* (____)(____)(_/\/\_)(____)(___/
*
* This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
*
* Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
*
* ======================================================================================
*/
#include <sstream>
#include <iostream>
void iterate_directory()
{
const auto dir = limes::files::dirs::cwd();
std::stringstream stream;
dir.iterateFiles ([&stream] (const limes::files::File& f)
{
for (const auto& line : f.loadAsLines())
{
std::cout << line << std::endl;
stream << line;
} });
const auto newFile = dir.getChildFile ("concat.txt");
newFile.overwrite (stream.str());
}
void iterateFiles(FileCallback &&callback, bool recurse=true, bool includeHiddenFiles=true) const
Calls a function for each child file that exists in this directory.
File getChildFile(const std::string_view &filename, bool createIfNeeded=false) const
Returns a File object representing a file in this directory with the specified name.
This class represents a file on the filesystem.
std::vector< std::string > loadAsLines() const
Loads the file's contents as a vector of strings, with each string containing the contents of one lin...
bool overwrite(const char *const data, std::size_t numBytes) const noexcept
Replaces the file's contents with the given data.
The main header for the limes_files library.