There are many types of structures of directory in the Operating System. The simplest one of them is Single Level Directory structure. In this type of structure, there is one user and there is a single root directory. Inside the root directory, there is a main entry directory responsible for a single file. All the files of the system are contained inside this main root directory. These main directories house all the files in the system. There can be no other sub-directories inside the main directories. Implementation of such a structure is very simple, and searching is also very easy. But this also has a big disadvantage which is that there cannot be two files of the same name. Even if the size of the files remains small, the size of the directory will be huge because a system has thousands of such files and all of these will be inside a single root directory.
Single Level Directory Program In C++
Output of Single Level Directory Program In C++
In the above program, the main () function is used to take the user name from the user. It is also responsible for taking the choice from the user repeatedly till the user enters 0 for exit. Pressing 1 calls the addDir () method which is used to add a directory inside the root folder. Pressing 2 calls the addFile () method, which will take the name of the directory inside which a file has to be created and then the name of the file and then it will create a file inside the respective directory. Pressing 3 will call the displayDirTree () method which will display the directory tree created by the user.