To practice with nested programming structures
Instructions
For this lab the goal is to design a program using pseudocode that has the ability to safely rename a file.
Available Commands
We can assume that our program will have a "change" command that can be given an existing filename and a new name and can then cause the filename to become the new name.
For example, we might have a file called test1.txt and we want to change it's name to sample.txt. We could, in our program design, say "change test1.txt to sample.txt" and the program would change the name of the file for us. Either of the two names could be represented with variable data.
Our program will also have the ability to tell if a specific name already exists. For example, "x1 exists?" would give a boolean value. Again, the filename used could be variable.
Validation
For our program to make the process of renaming a file safe, we need for it to not allow the user to rename a file in four situations.
- When the original file name doesn't exist (name given but there is no file in existence by that name)
- When the new file name does exist (there is already a file with that name so renaming the file will cause a collision)
- When the original file name is blank (ambiguous, we don't know what to rename from)
- When the new file name is blank (ambiguous, we don't know what to rename to)
If any of these conditions are found to exist the program should display a specific and informative error message and then exit. The user will NOT be give a second opportunity to enter the information. (no loops)
If none of those conditions exist then the filename should be changed.