File size: 973 Bytes
8e99893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os

def batch_iterable(iterable, batch_size):
    """Yield successive batches from iterable"""
    it = list(iterable).copy()
    for i in range(0, len(it), batch_size):
        yield it[i:i + batch_size]

def zip_folder(folder_path):
    """
    Reads all .txt files in the folder and returns them as a list of dictionaries.
    Wrapper name preserved from original code, though it returns content list.
    """
    if (len(folder_path) == 0) or (not os.path.exists(folder_path)):
        return None

    # Original code had references to creating a csv/zip but commented out.
    # We only reproduce the active logic.
    data = []

    for fname in os.listdir(folder_path):
        if fname.lower().endswith(".txt"):
            fpath = os.path.join(folder_path, fname)
            with open(fpath, "r", encoding="utf-8", errors="ignore") as f:
                content = f.read()
            data.append({"filename": fname, "content": content})

    return data