Nodes/Comfyui_PDuse/PD加载文本文件夹(输出列表)
ComfyUI Node

PD加载文本文件夹(输出列表)

Dump a folder of captions into a list — sorted, capped, paired with names

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD加载文本文件夹(输出列表)
    • text_list
    • concat_text
    • filename_text
    • file_count
    directory_path
    limit_count0

    If you've ever organized a training dataset, you know the pain: hundreds of .txt caption files sitting next to their images, and you need to read them all, in order, so the captions line up with the images. PD_LoadTextsFromDir ("PD加载文本文件夹(输出列表)" - "load text folder, output as list") is that loader: give it a folder path and it reads every text-ish file in it, sorted, and hands you the contents as a list, a single concatenated blob, the filenames, and a count. It's the text side of the batch-prep story this pack keeps telling, and it pairs directly with the folder image loader.

    It's from 7BEII/Comfyui_PDuse, the Chinese-authored utility pack. Display name is Chinese; class name is English. Fun.

    How it works

    It scans directory_path and keeps files with the extensions it cares about - txt, csv, json, md, py, js, bat, sh, xml, yaml - sorts them by name, and reads each one as UTF-8 text. Then it builds four outputs:

    • text_list - the file contents, one per file, as a list. This is the one you wire into a batch processor, index-aligned with whatever sorted filename list you have.
    • concat_text - every file's contents joined together as a single string. Handy when you want the whole dataset dumped into one prompt box or one file.
    • filename_text - the filenames, newline-joined.
    • file_count - how many files were read.

    The sorting is the quiet hero. Reading a folder unsorted gives you 10.txt, 100.txt, 11.txt order, which silently misaligns your captions from your images. This node sorts lexically like the image loader in the same pack does, so as long as your files are named consistently (001.txt …), the pairing holds.

    The inputs that matter

    • directory_path - the folder. Absolute path, real files.
    • limit_count - max files to read, 0 = unlimited.

    Missing or empty path doesn't crash: you get a one-element list [""], an empty string, an empty name string, and count = 0. Fail-soft, same house style as the pack's image loader - check file_count before trusting the output.

    Installing

    ComfyUI Manager, search Comfyui_PDuse; or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Restart. No models, no downloads - it's pure file I/O.

    Gotchas

    The usual pack quirks: Chinese README, and this node's display name is fully Chinese in the node menu, so search for the class PD_LoadTextsFromDir if you can't find it by the translated title. Non-recursive, and it reads any file with those extensions - including a stray data.json or notes.md you didn't mean to caption, which will shift your index alignment. And the sort is filename-based: if your images are 01_R.png but your captions are 1_R.txt, the two loaders will order them differently and the pairing silently breaks. Keep the naming scheme identical between images and text and this node is a genuinely handy batch-workflow workhorse.

    CategoryPDuse/Text

    Inputs (2)

    NameTypeDefaultDescription
    directory_pathSTRING
    limit_countINT00–10000

    Outputs (4)

    NameTypeDescription
    text_listSTRING
    concat_textSTRING
    filename_textSTRING
    file_countINT