Is there a way to check if a file exists (for now just on Windows) without incurring cost of opening it?
At the moment I am using:
ifstream ifile(FilePath);
if(ifile){
but the problem is I then put the file into boost mapped_region, thereby opening the file twice. It would be better if I could perform a check for the files existence without having to open it.
Remember that even if you do check and then try to open, there’s always a possibility that the file could be moved / deleted between you checking it and trying the open which is always a hazard with these kinds of operations.
It may be more efficient simply to open the file buffer as part of the creation of the mapped region but be prepared to catch the
interprocess_exceptionbeing thrown on error.