In: Physics
c# only please
Objectives
Tasks
This assignment has two parts:
Task 1 – File Input
The first piece of information we need is a text file’s name and location. Ask the user through the console what the file’s name and location are. After that, please ensure that the file does exist and at the given location. If the file does not exist or cannot be read, please return a message to the user stating that and ask them to enter another name and location.
Finally, if the file can be read then simply copy/read every line from the file. The contents of this file will be used in the next task.
Task 2 – File Output
Ask the user, through the console, what the name of the copy of the previous file should be called and where it should be saved. Check to see if a file with the same name already exists at the location given and if one does ask the user if they want to overwrite the file that already exists or if they would like to change the name and location of the new file. If they wish to change the name and location, go through the process of getting their input again through the console and checking if the newly given name and location are taken already too.
If they want to overwrite or no file already exists in the given location with the given name, then place the copied contents of the file that was read in the first task into this new file.
After successfully copying the contents of the first file into the second file, print to the console the name and location of both of those files.
A sample text file named “textfile.txt” has been supplied in case you need a file to test the above code on. The contents of that file is the declaration of independence.
∃ Some Sample Output:
Please enter a text file name and location:
C:\Users\source\repos\1322L_Assignment6\bin\Debug\textfiladsfe.txt22
This file does not exist!
Please enter a text file name and location:
C:\Users\source\repos\1322L_Assignment6\bin\Debug\textfile.txt
Please enter a new file name and location:
C:\Users\source\repos\1322L_Assignment6\bin\Debug\DeclarationOfIndependence.txt
A file already exists with that name!
Would you like to overwrite it or enter a different name? (0 or 1) 0
The file will be overwritten.
The file “C:\Users\source\repos\1322L_Assignment6\bin\Debug\textfile.txt” has been copied to “C:\Users\source\repos\1322L_Assignment6\bin\Debug\DeclarationOfIndependence.txt”.