#C6274. File System Simulation
File System Simulation
File System Simulation
You are tasked with simulating a simple file system that supports a series of commands. The system starts with only the root directory /
.
The supported commands are:
mkdir path
: Create a directory at the specified absolute path.touch path content
: Create a file at the specified absolute path with the given initial content.ls path
: List all files and subdirectories in the specified directory, sorted in lexicographical order. If the directory is empty, output(empty)
.cat path
: Display the content of the specified file.write path content
: Overwrite the content of the specified file with the new content.rm path
: Remove the file or directory at the specified path.
The commands are executed in the order given. Only the output of the ls
and cat
commands should be printed.
Note: When listing directory contents with ls
, if there are no files or directories, output (empty)
.
Example:
Input: 10 mkdir /home mkdir /home/user mkdir /home/user/docs touch /home/user/docs/file1 Hello ls /home/user cat /home/user/docs/file1 write /home/user/docs/file1 World cat /home/user/docs/file1 rm /home/user/docs ls /home/user</p>Output: docs Hello World (empty)
inputFormat
The first line contains a single integer n representing the number of commands. The following n lines each contain one command. Each command is one of the six commands described above.
outputFormat
For every ls
or cat
command encountered while processing the input, print the result on a separate line. For ls
, if the directory is empty, output (empty)
.## sample
10
mkdir /home
mkdir /home/user
mkdir /home/user/docs
touch /home/user/docs/file1 Hello
ls /home/user
cat /home/user/docs/file1
write /home/user/docs/file1 World
cat /home/user/docs/file1
rm /home/user/docs
ls /home/user
docs
Hello
World
(empty)
</p>