|
Boost Users : |
From: Michael Burr (burr2_at_[hidden])
Date: 2024-09-02 22:14:12
I'm having difficulty using boost/filesystem.hpp on a simple test example. If I understand things correctly, this code should see if it can find the files called "test_file" and "test_file2" in the current directory.
```
#include <boost/filesystem.hpp>
#include <iostream>
using namespace boost::filesystem;
int main()
{
path file1 = "test_file", file2 = "test_file2";
if(status(file1).type() == file_not_found)
std::cout << "First file not found\n";
if(status(file2).type() == file_not_found)
std::cout << "Second file not found\n";
return 0;
}
```
If I run the following,
```
touch test_file
g++ filesystem_check.cpp -lboost_filesystem
./a.out
```
the result is
> First file not found
> Second file not found
I expected only the second file to be not found. I arrived at this question because exists(file1) was returning false when I thought it should return true, and I traced the issue back to this check. I've also tried this example with an absolute path, and the results were the same.
This is using Boost 1.81 installed via macports on a mac with OS 12.5.1 (so slightly out-of-date OS). Is this a mac issue or am I missing something in my code?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net