Q:

C program to check a specified directory exists or not

0

C program to check a specified directory exists or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Given a path of the directory, we have to check whether the directory exists or not.

Program:

The source code to check a specified directory exists or not is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to check a specified directory 
// exist or not

#include <dirent.h>
#include <stdio.h>

int main(void)
{
    DIR* dObj;
    dObj = opendir("./image");

    if (dObj != NULL)
        printf("Directory exists.\n");
    else
        printf("Directory does not exists.\n");

    return 0;
}

Output:

Directory exists.

Explanation:

Here, we checked directory "image" exists in the current directory or not. Then print the appropriate message on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

File Handling Examples Programs in C language

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to check a specified file exists or not... >>
<< C program to print the list of files and subdirect...