Python Forum
Read Multiples Text Files get specific lines based criteria
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read Multiples Text Files get specific lines based criteria
#3
I don't undstand, at home I find way to solve my problem, but when I test this code at work does't work.

After run this code (change filepaths to my job computer), don't show D100 lines, showing nothing.

import glob
import pandas as pd

filepaths = glob.glob("/home/zinho/Downloads/*.txt")
lista = []

'''
Faz a leitura de vários arquivos txt
Copia as linhas baseado no critério |D100| e salva em um csv

'''

try:
    for fp in filepaths:
        with open(fp, 'r') as f:
            lin = f.readlines()
            for cnt in lin:
                if cnt[:6] == '|D100|':
                    lista.append(cnt)

# Essa linha cuida do final do arquivo com caracteres estrnhos
except UnicodeDecodeError:
    pass

df = pd.DataFrame(lista)
df.to_csv('/home/zinho/Downloads/Master.csv', index=False, header=False)
Reply


Messages In This Thread
RE: Read Multiples Text Files get specific lines based criteria - by zinho - May-18-2020, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 480 Feb-07-2024, 12:24 PM
Last Post: Viento
  filtering a list of dictionary as per given criteria jss 5 751 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Move Files based on partial Match mohamedsalih12 2 868 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Color a table cell based on specific text Creepy 11 2,112 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Making a question answering chatbot based on the files I upload into python. Joejones 1 1,286 May-19-2023, 03:09 PM
Last Post: deanhystad
  Read text file, modify it then write back Pavel_47 5 1,679 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  python print all files which contain specific word in it mg24 5 1,284 Jan-27-2023, 11:20 AM
Last Post: snippsat
  How to read in mulitple files efficiently garynewport 3 916 Jan-27-2023, 10:44 AM
Last Post: DeaD_EyE
  python move specific files from source to destination including duplicates mg24 3 1,138 Jan-21-2023, 04:21 AM
Last Post: deanhystad
  azure TTS from text files to mp3s mutantGOD 2 1,746 Jan-17-2023, 03:20 AM
Last Post: mutantGOD

Forum Jump:

User Panel Messages

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