Python Forum
using last 2 characters of a file name to identify it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using last 2 characters of a file name to identify it
#1
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:

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
Reply


Messages In This Thread
using last 2 characters of a file name to identify it - by CAD79 - Jul-11-2024, 03:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help to identify CNA for automation qatester 0 549 May-31-2024, 09:24 AM
Last Post: qatester
  identify not white pixels in bmp flash77 17 7,781 Nov-10-2023, 09:21 PM
Last Post: flash77
  error "cannot identify image file" part way through running hatflyer 0 1,994 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,685 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Need to identify only files created today. tester_V 5 7,368 Feb-18-2021, 06:32 AM
Last Post: tester_V
  Split Characters As Lines in File quest_ 3 3,405 Dec-28-2020, 09:31 AM
Last Post: quest_
  get two characters, count and print from a .txt file Pleiades 9 5,078 Oct-05-2020, 09:22 AM
Last Post: perfringo
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 2,958 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  Remove escape characters / Unicode characters from string DreamingInsanity 5 21,606 May-15-2020, 01:37 PM
Last Post: snippsat
  CSV file escaping characters lokhtar 2 4,434 Dec-09-2019, 06:48 PM
Last Post: lokhtar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020