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
#1
Greetings!
I have a list of error codes and I'm trying to find/count each error in each file and print them like this
"error - 1002x01 - 11"
"error - 1001x01 - 8"
and so on.
I wrote a code to do this but having a problem printing "error code - number of errors"

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                
                for e_ln in fto_read :           # reading each line from a file #
                    e_ln=e_ln.rstrip()
                    #print (e_ln)
                    for e_el in list :           # reading an element from the list #
                        if e_el in e_ln :
                            e_el=e_el.rstrip()
                            #print ("FOUND LINE --->> ",e_ln)
                            count+=1
                            print ("Error Name   ",e_el)
                print ("Number of Errors ---- >> ",count)
Reply


Messages In This Thread
List of error codes to find (and count) in all files in a directory - by tester_V - Dec-10-2020, 04:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 447 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Program to find Mode of a list PythonBoy 6 1,072 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Function to count words in a list up to and including Sam Oldman45 15 6,536 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Strange argument count error rowan_bradley 3 706 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  change directory of save of python files akbarza 3 874 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Coding error. Can't open directory EddieG 6 1,108 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,299 Jun-27-2023, 01:17 PM
Last Post: diver999
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 1,622 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,184 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  list the files using query in python arjunaram 0 669 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