python – PySimpleGUI FolderBrowse and searching for file type

The program is intended to use PySimpleGUI to open a folder, and then I have a function to search through the folder and store all the variants of step files within that folder and return a list of those step files. However, once the list of filepaths is generated, the step file is appended with two slashes “//” and windows can’t find the file when it is in that format. The code will follow:

    def stpFinder(source_dir):
        stp_files = []
        for root, dirs, files in os.walk(source_dir):
            for file in files:
                if file.endswith(".stp"):
                    stp_files.append(os.path.join(root, file))
                elif file.endswith(".step"):
                    stp_files.append(os.path.join(root, file))
        return stp_files


import PySimpleGUI as sg
import functions_new as fn

sg.theme("Default1")

input1 = sg.Input()
archive_choose = sg.FolderBrowse("Select Source Directory",
                                 key="source",
                                 pad=(5, 5))

input2 = sg.Input()
BOM_choose = sg.FileBrowse("Select BOM",
                           key="excel",
                           pad=(5, 5))

exec_button = sg.Button("Execute",
                        pad=(5, 5),
                        button_color=('White', 'NavyBlue'))

window = sg.Window(title="Step Name Replace",
                   layout=[[input1, archive_choose],
                           [input2, BOM_choose],
                           [exec_button]],
                   font=("Segoe UI Variable", 10))

while True:
    event, values = window.read()

    if event == sg.WIN_CLOSED or event == "Exit":
        break

    stp_files = fn.stpFinder(values['source'])
    print(stp_files)



window.close()

Example output: path/to/folder \ \ appendedfile.stp

I do not know where the 2 backslashes are coming from

Read more here: Source link