A simple demonstration of using fz::local_filesysThis example lists the contents of the directory given as argument to the program, or the current working directory if no argument is given.

#include <iostream>
#include <string.h>
int main(int argc, char *argv[])
fz::native_string path = fzT(".");
if (argc > 1 && argv[1] && *argv[1] && strlen(argv[1]) < 1000) {
path = fz::to_native(std::string(argv[1]));
// Begin listing
if (!fs.begin_find_files(path)) {
std::cerr << "Cannot list " << fz::to_string(path) << std::endl;
return 1;
std::cout << "Listing " << fz::to_string(path) << "\n";
std::cout << "----------------------------------\n";
int64_t size;
bool is_link;
int mode;
// Iterate over it
while (fs.get_next_file(name, is_link, t, &size, &time, &mode)) {
bool is_dir = t == fz::local_filesys::dir;
// Print results
std::cout << fz::to_string(name) << "\n";
std::cout << " Type: " << (is_link ? "symlinked" : "regular") << (is_dir ? " directory" : " file") << "\n";
if (!is_dir) {
if (size >= 0) {
std::cout << " Size: " << size << " octets" << "\n";
if (!time.empty()) {
std::cout << " Last modified: " << time.format("%Y-%m-%d %H-%M-%S ", fz::datetime::local) << "\n";
std::cout << " Mode: " << mode << "\n" << std::endl;
return 0;
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:41
bool empty() const
std::string format(std::string const &format, zone z) const
This class can be used to enumerate the contents of local directories and to query the metadata of fi...
Definition: local_filesys.hpp:26
Types of files. While 'everything is a file', a filename can refer to a file proper,...
Definition: local_filesys.hpp:38
result begin_find_files(native_string path, bool dirs_only=false, bool query_symlink_targets=true)
Begins enumerating a directory.
bool get_next_file(native_string &name)
Gets the next file in the directory. Call until it returns false.
Declares local_filesys class to enumerate local files and query their metadata such as type,...
size_t strlen(Char const *str)
Returns length of 0-terminated character sequence. Works with both narrow and wide-characters.
Definition: string.hpp:217
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:34
std::string to_string(std::wstring_view const &in)
Converts from std::wstring into std::string in system encoding.
native_string to_native(std::string_view const &in)
Converts std::string to native_string.
#define fzT(x)
Macro for a string literal in system-native character type. Note: Macro definition changes depending...
Definition: string.hpp:257