Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How to prevent the opening of a file that does not exist
How to prevent the opening of a file that does not exist [message #3774] Sat, 24 June 2006 13:26 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I'm opening a file for reading purpose with:

FileIn in(filename);

I would like to know which is the best method (in.IsOK(), in.IsError(), ...) to prevent the case in which the file doesn't exist.

Thank you,
Luigi
Re: How to prevent the opening of a file that does not exist [message #3775 is a reply to message #3774] Sat, 24 June 2006 16:42 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
forlano wrote on Sat, 24 June 2006 12:26

Hello,

I'm opening a file for reading purpose with:

FileIn in(filename);

I would like to know which is the best method (in.IsOK(), in.IsError(), ...) to prevent the case in which the file doesn't exist.

Thank you,
Luigi


maybe this?
bool FileExists(const char *name)
Re: How to prevent the opening of a file that does not exist [message #3776 is a reply to message #3775] Sat, 24 June 2006 19:57 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Sat, 24 June 2006 16:42


maybe this?
bool FileExists(const char *name)


Maybe yes. But I wonder what I must use if I want to use the same pointer "in" to perform this operation after the file opening. What is the difference between in.IsOK() and in.IsError()?

Luigi
Re: How to prevent the opening of a file that does not exist [message #3777 is a reply to message #3776] Sat, 24 June 2006 20:10 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
IsOK == !IsError

Anyway, for FileIn, I tend to use operator bool:

FileIn in(...);
if(in) {
   // in was succesfuly opened
}


Actually, IsError is usually used at the end of write operation to find out whether always was written OK (e.g. there is enough capacity on target media, like:

FileOut out(...);
if(out) {
   ...write the stuff
   if(out.IsError())
      Exclamation("Error writing the file !");
}


Mirek
Previous Topic: String - Unicode?
Next Topic: Translation Problems (German)
Goto Forum:
  


Current Time: Mon Apr 29 09:50:26 CEST 2024

Total time taken to generate the page: 0.01559 seconds