Single-level directory Program in CIn the operating system, directories can be organized in a variety of ways. Single Level Directory Structure is the most straightforward of them all. The root directory and the user are the only components of this kind of organization. A primary entry directory that places just one file is located inside the root directory. This system's primary root directory places all of the system's files. All system files are kept in these primary folders. Inside the primary directories, there cannot be any further subdirectories. Such a framework is quite easy to implement, and it makes searching very simple. The fact that there can never be two files with the same name, however, is a significant drawback of this. A system has hundreds of these files, all of which will be contained inside a single root directory. Thus, even if the number of files is tiny, the size of the directory will be enormous. The functionalities of this program allow for the insertion of files, deletion of files, searching for files, and display of existing files. Example:Let's take a program to demonstrate the single-level directory in C: Output: Enter the directory name: myfolder choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>1 Enter the File name: hii.txt choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>1 Enter the File name: newone.c choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>1 Enter the File name: lastone.txt choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>2 +------------------------+ Directory files | +------------------------+ myfolder hii.txt newone.c lastone.txt +------------------------+ choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>4 Enter the file name to be searched:newone.c The particular File is found at position 2 choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>3 Enter the file name to be deleted: lastone.txt lastone.txt is deleted. choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>2 +------------------------+ Directory files | +------------------------+ myfolder hii.txt newone.c +------------------------+ choose the option 1:Inserting the file 2:Displaying All Files 3:Deleting the File 4:Searching the File 5:Exit >>5 Explanation:
Case 1: Add a file to the directory. Case 2: Show the directory's files. Case 3: Delete a file from the directory. Case 4: Check the directory for a file. Case 5: Use exit(0) to end the program. This code offers a straightforward command-line interface to control files inside a directory. It is a basic example for educational purposes because it lacks error handling and does not maintain data across program runs. Next TopicC Programming Test |