Boost logo

Boost Users :

From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2007-04-26 09:35:57


Johan Nilsson wrote:
> Jeff wrote:
>> Hello,
>>
>> I can see from a FileSystem example how to check for the existence of
>> a directory. What I would like to be able to do is to check for the
>> existence of a file but I couldn't figure out how to do it using
>> exists().
>>
>> The way that I currently check for a file's existence is by opening
>> the file. I wonder if boost::filesystem can test for a file's
>> existence more efficiently than having to open it like I do in the
>> snippet below.
>>
>> // checking for file existence by opening the file
>> ifstream source(fileName);
>> if (source)
>> ...
>
> What about (Boost 1.34):
>
> #include <boost/filesystem.hpp>
>
> ...
>
> boost::filesystem::exists(fileName);

Oops, I didn't read the first part of the question. See other poster's
reply.

/ Johan


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