Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a directory In C or C++

Tags:

c++

c

How to create a directory with C code (other than the method of forking and using mkdir) ? Is there anything like dirent.h? dirent.h only allows to read directories. (without using external library)

like image 201
avd Avatar asked Feb 13 '10 08:02

avd


People also ask

What is a directory in C?

The directory holds all that information, such as the file's physical location, its name, timestamps, permissions, and other trivia. These details are accessible when you use the proper C language functions. To access a directory, use the opendir() function. It's prototyped in the dirent.

How does mkdir work in C?

The mkdir function creates a new, empty directory with name filename . The argument mode specifies the file permissions for the new directory file. See The Mode Bits for Access Permission, for more information about this. Write permission is denied for the parent directory in which the new directory is to be added.

How do you create a file in C?

To create a file in a 'C' program following syntax is used, FILE *fp; fp = fopen ("file_name", "mode"); In the above syntax, the file is a data structure which is defined in the standard library. fopen is a standard function which is used to open a file.

Can we create directory in Linux?

The mkdir command in Linux/Unix allows users to create or make new directories. mkdir stands for “make directory.” With mkdir , you can also set permissions, create multiple directories (folders) at once, and much more.


1 Answers

Use the mkdir function.

#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname, mode_t mode);
like image 169
Douglas Leeder Avatar answered Sep 29 '22 10:09

Douglas Leeder