The basic information about the files and sub-directories for one person are stored in a file. Each file or directory for the person is listed on a separate line with one character indicating whether the entry is a file or a directory. After the last file of a directory, there is a line with an 'e' on it to indicate the end of that directory. The order of the files and directories are as if one had done a depth-first search on the structure; here is an example, showing what is in the file smtree.txt On the left is what appears in the file; in the middle is the logical view of the directory as Windows Explorer might display it; at the right is the logical view after the actions described below. Note that root is always the name of the top-level directory; other names may vary.
d root
root
root
f file1
file1
file1
f file2
file2
file6
d dir3
dir3
dir7
f file4
file4
file9
f file5
file5
dir3
e
file6
file4
f file6
dir7
file5
d dir7
file8
file11
f file8
file9
file2
f file9
file10
file10
e
file11
file8
f file10
f file11
e
You are to write a program that reads in the directory structure from a file, accepts and processes four "move" commands from the keyboard, and then displays the directory structure in the "Windows Explorer form" shown above. All files and directories in the structure have unique names. Consequently, the move commands consist of only a source name (file or directory to be moved) and a destination directory where the component is to be placed. Anything moved to the destination should become the last entry in that directory. If the source is a directory, naturally, all of its substructure should be moved with it. Here are example moves for the directory structure shown in the middle above. The structure at the right shows the directory after the moves have taken place.
file11 dir3
Moves file11 to be placed after file5 in dir3
file2 dir3
Moves file2 after file11
file8 root
Moves file8 from dir7 to be placed after file10 in root
dir3 dir7
Moves all of dir3 to after file9 in dir7
Your program should accept through the
keyboard the name of the file holding the initial directory structure.
You may assume that there will be no more than 6 levels to the directory
structure, both before and after the move operations. The example
above started with two levels and ended with three.