- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I create directory tree using C++ in Linux?
In this section we will see how to create a directory tree using C++ code in Linux. In Linux terminal we can put some command like “mkdir –p /dir/dir1/dir2” Here –p is used to mark as parent (recursively create inner directories).
In C++ code we can use some libraries of Linux system. Then we can use Linux terminal commands as string argument of the system() function. We can create directory tree like this.
Example
#include <bits/stdc++.h> #include <iostream> #include <sys/stat.h> #include <sys/types.h> using namespace std; int main() { int status; status = system("mkdir -p TP/My_Folder/test"); // Creating a directory if (status == -1) cerr << "Error : " << strerror(errno) << endl; else cout << "Directories are created" << endl; }
Output
Directories are created
If we check manually, we can get the directories inside the current directory.
- Related Articles
- How to create a new directory in Linux using the terminal?
- How can I create a directory if it does not exist using Python?
- How can I get the list of files in a directory using C/C++?
- How to create a Directory using C#?
- How can I get the list of files in a directory using C or C++?
- How to Create a Shared Directory for All Users in Linux?
- How can I create a python directory if it does not exist?
- How can I profile C++ code running in Linux?
- How to create a zip file and ignore directory structure in Linux?
- How can I profile C++ code running on Linux?
- How to create a directory using Python?
- How to create a directory using Java?
- How to create a directory recursively using Python?
- How to create a directory hierarchy using Java?
- How to create a Directory recursively using Java?

Advertisements