$25
CSE 102 Programming Assignment 8
Description
• Your program reads two files:
– files.txt
– commands.txt
• According to content in files.txt, the program dynamically creates a directory structure and evaluates the commands listed in commands.txt.
• Your program prints the list of files and directories with their full addresses to a file called output.txt. files.txt
• Each line is a file or directory name. This file lists all the necessary information for you to create a full directory structure. There won’t be any errors but the order can be arbitrary. You have to figure out the root directory and the rest of the hierarchy from this file. For this initial file, you can assume all the directory names will be unique. You can read the file line by line and create independent structures for each line, then you can combine all the created structures in order to create the final structure. Assume, there isn’t any empty directory. Each line ends with a file name.
• Example:
• Below is the contents of a files.txt file:
directory1/directory2/file1 directory2/file3 directory0/directory1/file5 directory0/file4
• For this example, the structure is as follows:
directory0 directory1 directory2 file1 file3
file5
file4
commands.txt
This file includes several commands which work on the directory structure you read from files.txt. Each line is a command. The following should be recognized:
copy A B move A B delete A cd A copy A B
This command has two operants: A and B. B is a directory. A can be a directory or a file. This command copies
A and places it under directory B. If A is a directory, all the structure under A is copied under B. A and B can be provided as full directory or relative directory.
move A B
Similar to copy A B. This moves A under B and deletes the original copy of A delete A
Removes A from the structure.
cd A
This command changes the current directory to A. A is definitely a directory not a file. There are special replacements for A:
• .. : changes the current director to the parent directory.(If there is no parent, current directory does not change)
• / : changes the current directory to root. Root directory is the top directory. There isn’t a parent directory above the root directory.
Example:
Assume that your program reads the example files.txt given above. Current directory is the top(root) directory which is directory0
• Issuing the command copy /directory0/directory1/directory2/file1 /directory0, copies file1 and places it under directory0. Following is the result of this command:
directory0 directory1 directory2 file1 file3
file5 file1 file4
• similarly, the command copy file4 directory1 copies file4 to the directory directory1. Here, current directory is directory0 so, file4 and directory1 are given as relative addresses. After this command, the structure changes to the following version:
directory0 directory1 directory2 file1 file3
file4 file5 file1 file4
• If there is a command delete directory1, it will change the structure as follows:
directory0 file1 file4
output.txt
This file lists all the files and directories with their full addresses. If your directory structure is as follows:
directory0 directory1 directory2 file1 file3 file4 file5 file1 file4
You should create the following output.txt file:
directory0 directory0/directory1 directory0/file1 directory0/file4 directory0/directory1/directory2 directory0/directory1/file4 directory0/directory1/file5 directory0/directory1/directory2/file1 directory0/directory1/directory2/file4
• The order is not important.