Copy paste file to another folder

Hello everyone,

I have written code to copy and paste a file to another folder. It works perfectly when I run it on my localhost, but unfortunately, it fails when someone else tries to use my app on a different computer. I encountered a “FileNotFoundError” with the following error message: [WinError 3] The system cannot find the path specified.

The error occurs in the following line of code: files = os.listdir(folder_path) .

Here is the relevant portion of my code related to file copying:

Could you please provide assistance or suggestions on how to resolve this issue? Thank you.

#Retrieves the list of file names from the specified folder path
def get_file_names(folder_path):
    st.write(f"Folder path: '{folder_path}'")  # Debug line
    files = os.listdir(folder_path)
    return files

#Copies a file from the original folder to the target folder.
def copy_file(original_folder, target_folder, filename):
    original_path = os.path.join(original_folder, filename)
    target_path = os.path.join(target_folder, filename)
    shutil.copyfile(original_path, target_path)


            # Add inputs for file copy
            original_folder = st.text_input('Enter your original folder path:')
            target_folder = st.text_input('Enter your target folder path:')
            if original_folder and target_folder:
                files = get_file_names(original_folder)
                selected_file = st.selectbox('Select a file to copy:', files)

            confirm_add = st.checkbox("Confirm add record")
            if st.button("Add") and confirm_add:
                add_record(conn, table_name, values)
                if original_folder and target_folder and selected_file:
                    copy_file(original_folder, target_folder, selected_file)
                    st.success(f"File {selected_file} copied successfully!")

That is probably because the path you entered as original_folder does not exist.