Look at stat
for checking if the directory exists,
And mkdir
, to create a directory.
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> struct stat st = {0}; if (stat("/some/directory", &st) == -1) { mkdir("/some/directory", 0700); }
You can see the manual of these functions with the man 2 stat
and man 2 mkdir
commands.
Related Posts:
- How do I find all files containing specific text on Linux?
- How to extract C source code from .so file?
- How to change permissions for a folder and its subfolders/files in one step
- How to change permissions for a folder and its subfolders/files in one step
- Implementing shell in C and need help handling input/output redirection
- Read and write to binary files in C?
- Writing a simple shell in C using fork/execvp
- Implementation of multiple pipes in C
- configure: error: cannot run C compiled programs
- Can’t remove a directory in Unix
- Is there an alternative sleep function in C to milliseconds?
- C fopen vs open
- error : storage class specified for parameter
- Wait for user input in C?
- Difference between exec, execvp, execl, execv?
- cd into directory without having permission
- Meaning of directories on Unix and Unix like systems
- How to copy file preserving directory path in Linux?
- How do I deal with a filename that starts with the hyphen (-) character?
- Chmod 777 to a folder and all contents [duplicate]
- Bash: No such file or directory?
- Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
- Confused about stdin, stdout and stderr?
- What’s a .sh file?
- Amazon Linux: apt-get: command not found
- How to set the environmental variable LD_LIBRARY_PATH in linux
- What’s a .sh file?
- Why does ENOENT mean “No such file or directory”?
- How can I symlink a file in Linux? [closed]
- How to fix ‘sudo: no tty present and no askpass program specified’ error?
- Kill detached screen session [closed]
- Undefined reference to pthread_create in Linux
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- How do I grep recursively?
- How do I grep recursively?
- Openssl : error “self signed certificate in certificate chain”
- Why do you need to put #!/bin/bash at the beginning of a script file?
- How to get the url of the current svn repo?
- What does pss mean in /proc/pid/smaps
- apt-get error: Sub-process /usr/bin/dpkg returned an error code (1)
- How to unmount a busy device
- “Couldn’t find a file descriptor referring to the console” on Ubuntu bash on Windows
- How to unmount a busy device
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- performing HTTP requests with cURL (using PROXY)
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- Where can I find php.ini?
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
- Write to .txt file?
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- No space left on device
- How do I grep recursively?
- How can I recursively find all files in current and subfolders based on wildcard matching?
- How to perform grep operation on all files in a directory?
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- What is the LD_PRELOAD trick?
- Amazon Linux: apt-get: command not found
- How to install grub after installing Windows 10
- Linux: ‘Username’ is not in the sudoers file. This incident will be reported
- how to find libstdc++.so.6: that contain GLIBCXX_3.4.19 for RHEL 6?
- How to print pthread_t
- Pass a password to ssh in pure bash
- subprocess.Popen(): OSError: [Errno 8] Exec format error in python?
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- How to substitute shell variables in complex text files
- -bash: syntax error near unexpected token `newline’ for display command
- How can I recursively find all files in current and subfolders based on wildcard matching?
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- connect Error: “No route to host”
- SSH using python script
- Curl command for https ( SSL )
- How can I exclude directories from grep -R?
- How to exclude a directory in find . command
- “sed” command in bash
- How can I exclude directories from grep -R?
- Changing the resolution of a VNC session in linux
- gcc: error: unrecognized command line option
- How to exclude a directory in find . command
- How can I find all *.js file in directory recursively in Linux?
- mysql_config not found when installing mysqldb python interface
- Linux error while loading shared libraries: cannot open shared object file: No such file or directory
- How to set proxy for wget?
- Shell command to tar directory excluding certain files/folders
- Argument list too long error for rm, cp, mv commands
- QEMU: /bin/sh: can’t access tty; job control turned off
- Difference between using “chmod a+x” and “chmod 755”
- Explaining the ‘find -mtime’ command
- Meaning of exit status 1 returned by linux command
- Building HelloWorld C++ Program in Linux with ncurses
- How does “cat << EOF" work in bash?
- ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
- Docker can’t connect to docker daemon
- Need a good hex editor for Linux
- Pseudo-terminal will not be allocated because stdin is not a terminal
- tar removing leading ‘/’ from member names
- X11 forwarding request failed on channel 0
- The difference between stdout and STDOUT_FILENO
- WSL – GEDIT Unable to init server: Could not connect: Connection refused
- Python subprocess.Popen “OSError: [Errno 12] Cannot allocate memory”
- Install tkinter for Python