Question: IN JAVA Write a program to process some basic commands for file and directory manipulation in operating systems. Operating systems typically allow a user to

IN JAVA Write a program to process some basic commands for file and directory manipulation in
operating systems. Operating systems typically allow a user to organize files in a hierarchical (tree
structure) fashion. This provides better organization and makes it easy to locate a file. The commands
are as follows:
init
This command appears at the beginning of the input to indicate initialization (starting an empty file
system). An empty file system contains only the 'root' directory, which is always designated as '/home'.
This will also become the current directory. The init command is used later in the input when one wants
to start with an empty file system again (all files and directories are deleted).
end
This command indicates the end of input (program terminates).
mkfile filename
COSC 2436 S24
5
This command creates a file in the current directory. The filename will be in the range [1,10] characters
long and consists of only letters (upper and lower case) and digits.
mkdir dirname
This command creates a directory (subdirectory) in the current directory. The dirname will be in the range
[1,10] characters long and consists of only letters (upper case and lower case) and digits. The mkdir
command will not be used to create more than five levels of subdirectories in the file system hierarchy
(the file system hierarchy will have at most five levels not including the root directory).
cd path
This command is used to change to a different directory. The path can be '..' which indicates go up to
the parent directory, a dirname which goes down to the specified subdirectory, or any combination of
'..' and dirnames, separated by '/', to go up and/or down the tree multiple times in one command.
There will be at most five '/' in path, and the result will always be a valid directory.
ls
This command is used to list the file/directory names in the current directory. List the names in increasing
order. Assume that there will be at most 20 distinct names (at most 20 file/directory names in any
directory), and no more than 5000 user-created names in the entire file system. If the current directory is
empty (contains no files or directories), print a message indicating so.
Input will be from a data file where an input command starts in column one. If an input line
consists of two parts, there will be exactly one space separating the two parts. Only the commands init
and ls produce output to the screen. The init command generates only a heading. The ls command
generates a heading and the information requested. Note, for ls, the heading includes the current
directory. At the top level, this will be /home. At the lower levels, it includes the rest of the path as well.
Assume that every file system will have one or more ls commands (there will be one or more ls after
each init). The file is terminated with the end command.
Output to the screen the appropriate file system listings formatted according to the sample shown
below. Let the user input the file name from the keyboard. Finally, the program should ask if the user
wants to run the program again (Check case). Use a tree data structure. Refer to the sample output
below.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!