Question: Create a text file (with an editor such as Microsoft NotePad) named TwoYearsBeforeTheMast.txt which contains this text: Six days shalt thou labor and do all
Create a text file (with an editor such as Microsoft NotePad) named TwoYearsBeforeTheMast.txt which contains this text:
Six days shalt thou labor and do all thou art able, and on the seventh—holystone the decks and scrape the cable.
Implement a program that creates a directory named RichardHenryDana that resides as a subdirectory in the current directory. The program moves the text file from the current directory to the new subdirectory.
In your program, instantiate one Path object for the TwoYearsBeforeTheMast.txt file and instantiate another Path object for the RichardHenryDana subdirectory. Then use those two paths with the resolve method to create a destination Path object for where the file is supposed to go. Next, check to see if the subdirectory already exists, and if it does not, create the new subdirectory. Then attempt to move the file to the subdirectory. Use a try-catch mechanism to handle failure.
Step by Step Solution
3.39 Rating (180 Votes )
There are 3 Steps involved in it
Here is a Python program using the os and shutil libraries to achieve what youre asking This program ... View full answer
Get step-by-step solutions from verified subject matter experts
