Jump to content
  • Advertisement

Archived

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

dansteph

Best code to check if a file is present

This topic is 5997 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!