1

I'm writing a script which deletes old backup files. I've included filesystem as I would normally do, but this time, I got this error:

fatal error: filesystem: No such file or directory

I tried to include experimental/filesystem and I set -lstdc++fs as GCC flag. Nothing has worked for me.

Example code:

#include <cstdlib>
#include <algorithm>
#include <vector>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
    fs::path const directory{ "C:\Test" };
    std::vector<fs::directory_entry>::size_type const num_files_to_keep{ 5 };
    ...
Olivia Stork
  • 4,660
  • 5
  • 27
  • 40

1 Answers1

1

Using CodeBlocks ang GCC 8.0 or above You need to set c++17 compiler option (I'm using CodeBlock last Nightly build). Project build options

Then you must add to the Linker settings options the stdc++fs library.Linker settings

And then you must add the #include <filesystem> directive, from GCC 8.0, and not <experimental/filesystem>
On windows the directory separator is \\ (two backslash).
You need to write:

fs::path const directory { "C:\\Test" };
Sergio
  • 891
  • 9
  • 27