Thread: Checking File Existance

  1. #1

    Checking File Existance

    Hey everyone...

    Is there any way to check if a file exists?

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Check for existence when you try to open it perhaps? As in the following code, if opening returns NULL, it ain't where you're lookin for it, or can't be opened for some other reason.
    #include <stdio.h>
    int main(void)
       FILE *in
       if ((in = fopen("\\AUTOEXEC.BAT", "r"))
           == NULL)
          printf("Cannot open input file.\n");
          return 1;
    return 0;

  3. #3
    Registered User
    Join Date
    Apr 2002
    Here's one way of doing it:
    #include <stdio.h>
    int main ()
    FILE *fp;
    if ((fp=fopen("c:\\test.bin", "r")) == NULL)
      return 0;
    Last edited by jizzer; 04-25-2002 at 01:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. archive format
    By Nor in forum A Brief History of
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM