Mar-22-2022, 03:39 PM
(This post was last modified: Mar-22-2022, 06:20 PM by Yoriz.
Edit Reason: Added code tags
)
Hey guys!
I would like a bit of help please.
In short, I'd like
-User input, naming a file
-Automatically add the .txt extension
-If the file exists in the folder <A>, overwrite it
-Then move it to the appropriate folder <B>
-If the file exists in the destination folder <B>, overwrite it
The end goal is to have a .txt file where a dictionary will dump its content into it, acting as a database in the drive/folder I want it to be in.
Here's my code so far. I'm taking into consideration that the fille will be abc.txt
Obviously, I am forcing the user to add the extension manually, which I ultimately don't want to do.
Also, if the file exists, it won't be created or moved which I would like to force and squash.
I would like a bit of help please.
In short, I'd like
-User input, naming a file
-Automatically add the .txt extension
-If the file exists in the folder <A>, overwrite it
-Then move it to the appropriate folder <B>
-If the file exists in the destination folder <B>, overwrite it
The end goal is to have a .txt file where a dictionary will dump its content into it, acting as a database in the drive/folder I want it to be in.
Here's my code so far. I'm taking into consideration that the fille will be abc.txt
Obviously, I am forcing the user to add the extension manually, which I ultimately don't want to do.
Also, if the file exists, it won't be created or moved which I would like to force and squash.
def create_file(): input_1_5 = str(input("Creating file / Please enter a filename with its extension: ")) f = open(input_1_5, "x") create_file() def move_file(): import shutil shutil.move("H:/Github/abc.txt", "H:/Github/School-Exercises") move_file()Thank you!