For an application I'm creating, a combobox displays all customer names that are inside the active customer orders directory. In the customer order, there is mechanical, electrical etc and sales, which has the order acknowledgement. All customer sales order acknowledgment files have OA at the end of the file, but the start of the name may differ from the customer directory name. For example:
Customer directory name: 937298 Sea World
OA file: 937298 SeaWorld OA.pdf
As you can see, there is no space, which is different (sometimes the naming can be very different, this is just a minor example). Implementing a naming convention would be an option, but would require people to actually listen, and it would be better in the long run to be able to just find and print the order acknowledgement by using the OA at the end of the file. Is there a way I can do this? I was originally using the .get() function which would just use the customer name from the directory, but this is inconsistent due to inconsistent naming. How can I find the file I want by just using OA.pdf at the end of the file? Thank you. Here is my code:
Customer directory name: 937298 Sea World
OA file: 937298 SeaWorld OA.pdf
As you can see, there is no space, which is different (sometimes the naming can be very different, this is just a minor example). Implementing a naming convention would be an option, but would require people to actually listen, and it would be better in the long run to be able to just find and print the order acknowledgement by using the OA at the end of the file. Is there a way I can do this? I was originally using the .get() function which would just use the customer name from the directory, but this is inconsistent due to inconsistent naming. How can I find the file I want by just using OA.pdf at the end of the file? Thank you. Here is my code:
import os import tkinter as tk from tkinter import ttk class JobFileAutomation: def __init__(self): customer_path = os.listdir('Y:/orders/C-Active Orders/') self.root = tk.Tk() self.root.geometry('400x100') self.root.title('Job File Creator') self.root.iconbitmap('E:/jobFile.ico') self.mainframe = tk.Frame(self.root, background='white') self.mainframe.pack(fill='both', expand=True) self.customer_label = ttk.Label(self.mainframe, text='Select customer: ', background='white') self.customer_label.grid(row=0, column=0, padx=70) self.customer_selection = ttk.Combobox(self.mainframe, values=customer_path, width=40) self.customer_selection.grid(row=1, column=0, padx=10, pady=10) create_button = ttk.Button(self.mainframe, text='Create', command=self.create_job_file) create_button.grid(row=1, column=3) self.root.mainloop() return def create_job_file(self): customer_name = self.customer_selection.get() # name of file path oa_file = f"Y:/orders/C-Active Orders/{customer_name}/1-Sales/{customer_name} OA.pdf" os.startfile(oa_file, "print") print(customer_name) if __name__ == '__main__': JobFileAutomation()Edit: never mind, I got it. Being a C++/Arduino programmer has hard wired my brain into thinking these problems will be difficult to solve