0

trying to move a text file to a created folder using shutil.move() results in the error shutil.Error: Destination path 'C:\Users\user\Desktop\VSC_projects\website.txt' already exists

the code is as follows :

import os
import shutil

CURRENT_PATH = os.getcwd()
FOLDER_NAME = ""
WEBSITE = ""

def create_project_folder():
    while True:
        FOLDER_NAME = input("Please enter your project name: ")
        if not os.path.exists(FOLDER_NAME):
            print(f"Creating {FOLDER_NAME}")
            os.makedirs(FOLDER_NAME)
            print(f"{FOLDER_NAME} has been created")
            break
        if os.path.exists(FOLDER_NAME):
            print("Folder already exists. Please enter a diffrent folder name.")

def get_website_name():
    WEBSITE = input("Please type the website (note: include \"https://\"): ")
    if not os.path.isfile(WEBSITE):
        maker = open("website.txt","x")
        maker = open("website.txt","w")
        maker.write(f"{WEBSITE}")
        maker.close()

def move_files():
    folder_location = pathlib.Path(rf"{CURRENT_PATH}\{FOLDER_NAME}")
    file_location = pathlib.Path(rf"{CURRENT_PATH}\website.txt")

    shutil.move(file_location,folder_location)


def main():
    create_project_folder()
    get_website_name()
    move_files()

main()

what I'm confused about is that the destination path is not the one specified in the error massage.

Aryan
  • 43
  • 2
  • 6

0 Answers0