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
#8
I finallyI figured out where to move the:
if count > 0:
    print(f"{cur_ef}: {e_el} - {count}")
And now it almost does what I need, it prints:
1001x03 - 2
1001x03 - 2
It should print :
100x02- 2
1001x03 - 2

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
                if count > 0:
                    print(f"{e_el} - {count}")
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, 01:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through all files in a directory? Winfried 10 466 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 479 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Program to find Mode of a list PythonBoy 6 1,151 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Function to count words in a list up to and including Sam Oldman45 15 6,706 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Strange argument count error rowan_bradley 3 753 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  change directory of save of python files akbarza 3 919 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Coding error. Can't open directory EddieG 6 1,146 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,441 Jun-27-2023, 01:17 PM
Last Post: diver999
  Monitoring a Directory for new mkv and mp4 Files lastyle 3 1,671 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,269 Apr-05-2023, 07:36 PM
Last Post: Frankduc

Forum Jump:

User Panel Messages

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