Archived

This topic is now archived and is closed to further replies.

dansteph

Best code to check if a file is present

Recommended Posts

I don''t want to rely on return code of Dx8 loadtexture for some reason and also while in debug mode it return some "file is missing" in the debug windows wich will let me miss some real file missing... For now I use:
  
BOOL CheckFile(char* Filename)
{
      FILE *	stream;
      stream  = fopen(Filename, "rb" );
      if(stream==NULL)
           return FALSE;
      fclose( stream );
return TRUE
}
  
Is there any better method ? faster, more reliable ? any downside with the previous method ? Thanks Dan

Share this post


Link to post
Share on other sites
Your way works and is quite fast. The only better way I can think of off the top is if you are using C++ Builder. If so, just do this: "if (FileExists (FileName))". That will be slightly faster and is also slightly cleaner.

Share this post


Link to post
Share on other sites
Your way works and is quite fast. The only better way I can think of off the top is if you are using C++ Builder. If so, just do this: "if (FileExists (FileName))". That will be slightly faster and is also slightly cleaner.

Share this post


Link to post
Share on other sites

CheckFile() doesn''t work all the time. For example, a
file exists but you don''t have read permission.


Premature optimizations can only slow down your project even more.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What do you mean fast? You mean small amount of code right? I mean how much faster or slower can it be. You meant speed in regard to programming and not in regard to program execution right?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What do you mean fast? You mean small amount of code right? I mean how much faster or slower can it be. You meant speed in regard to programming and not in regard to program execution right?

Share this post


Link to post
Share on other sites