Python Forum
List of error codes to find (and count) in all files in a directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of error codes to find (and count) in all files in a directory
#9
Bowlofred! You pushed me in the right direction!
I think I fixed my script and it does what I want now.
It finds all the 'error codes' from the list in all my log files and prints them out in the format I want:
3-100x02
2-1001x03
Here is a final version of the snippet:

import os

list = ['100x02','1001x03']   # list of errors#
path = 'C:\\02'
for root,dirs, files in os.walk(path):
    for ef in  files :
        cur_ef = os.path.join(path,ef)
        if os.path.isfile(cur_ef):

            with open (cur_ef,'r') as fto_read  :
                count = 0
                er_nm = []
                for e_ln in fto_read :           # reading each line from a file #
                    for e_el in list :           # reading an element from the list #
                        if e_el in e_ln :
                            e_el=e_el.rstrip()
                            er_nm.append(e_el)
                            count+=1
                if count > 0:            
                    print ("Number of Errors - Name ---- >> ",str(count)+'-'+er_nm[0])

Thank you again for all your help!
I really appreciate it, you guys make my life easier.
Reply


Messages In This Thread
RE: List of error codes to find (and count) in all files in a directory - by tester_V - Dec-11-2020, 07:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 449 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Program to find Mode of a list PythonBoy 6 1,077 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Function to count words in a list up to and including Sam Oldman45 15 6,556 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Strange argument count error rowan_bradley 3 710 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  change directory of save of python files akbarza 3 876 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Coding error. Can't open directory EddieG 6 1,109 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,307 Jun-27-2023, 01:17 PM
Last Post: diver999
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 1,627 May-07-2023, 12:33 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,198 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  list the files using query in python arjunaram 0 670 Mar-28-2023, 02:39 PM
Last Post: arjunaram

Forum Jump:

User Panel Messages

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