# 在一个界面浏览多个文本文件的工具或方法？

**URL:** <https://meta.appinn.net/t/topic/26276>\
**Category:** 问题求助\
**Tags:** windows, 文本处理\
**Created:** [2021 年9 月 25 日 17:14 UTC](https://meta.appinn.net/t/topic/26276 "2021-09-25T17:14:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

作者： ![jerrylus](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/jerrylus/32/14901_2.png) [@jerrylus](https://meta.appinn.net/u/jerrylus)\
发布日期： [2021 年9 月 25 日 17:14 UTC](https://meta.appinn.net/t/topic/26276/1 "2021-09-25T17:14:47Z")

</div>

手头有一个数据目录，里面有很多 txt 文件，每个文件不长，大概 10 行以内，现在需要按照创建时间顺序依次浏览这些文件，得到一个类似于时间线的界面（见下图）。虽然可以手动把多个文件合并成一个文件，然后加时间戳分割，但是想看看有没有现有的工具存在。

（图片中软件：[Migi](https://focusapp.ink/#/Migi)）

 ![image](https://meta.appinn.net/uploads/default/original/3X/9/b/9bbf9cc6f39a89ea1482a821c2af8fa071c7dec4.png)

---

<div class="post-metadata">

作者： ![cuiliang](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/cuiliang/32/46680_2.png) [@cuiliang](https://meta.appinn.net/u/cuiliang)\
发布日期： [2021 年9 月 26 日 00:51 UTC](https://meta.appinn.net/t/topic/26276/3 "2021-09-26T00:51:16Z")

</div>

做了个简单的Quicker动作可以试试。

> **[合并预览 - by CL - 动作信息 - Quicker](https://getquicker.net/Sharedaction?code=8ab90946-e320-4df1-a7c3-08d97fc56787)**
>
> Quicker，Windows效率工具。快速触发 + 自动化。

原理比较简单，一共3步，（1）获得选中的文件路径列表。（2）根据创建时间排序并读取内容合并到一个大的文本中。（3）显示这个文本。 主要是2涉及到一点代码。

![](https://meta.appinn.net/uploads/default/original/3X/b/7/b78d12a342911e0040b0e8c7fe431deb12ad4393.gif)

---

<div class="post-metadata">

作者： ![yazii](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/yazii/32/13871_2.png) [@yazii](https://meta.appinn.net/u/yazii)\
发布日期： [2021 年9 月 26 日 02:57 UTC](https://meta.appinn.net/t/topic/26276/4 "2021-09-26T02:57:41Z")

</div>

我又想起了之前的问题

> [@牛年第一问：有自动整理相似数据/LOG的软件嘛？](https://meta.appinn.net/t/topic/21853):
>
> 工作中会使用一些软件，他们会产生大量数据，并且以一定的内容结构保存为多行log，或者txt，或者csv，或者excel。 这些数据要看也能看，但是如果几十笔数据需要分析对比，往往需要文本编辑器打开，用正则或者什么东西批量替换预处理一下，再粘贴到excel，再用筛选把相似的小节合并到一起。操作相当繁琐费事。 所以有没有软件能够自动分析多个文件，自动解析出数据结构，然后我可以对所有文件中的某一项的数据进行快速查看比较呢？

---

<div class="post-metadata">

作者： ![jerrylus](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/jerrylus/32/14901_2.png) [@jerrylus](https://meta.appinn.net/u/jerrylus)\
发布日期： [2021 年9 月 26 日 09:45 UTC](https://meta.appinn.net/t/topic/26276/5 "2021-09-26T09:45:52Z")

</div>

看起来不错！

---

<div class="post-metadata">

作者： ![jerrylus](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/jerrylus/32/14901_2.png) [@jerrylus](https://meta.appinn.net/u/jerrylus)\
发布日期： [2021 年9 月 26 日 09:55 UTC](https://meta.appinn.net/t/topic/26276/6 "2021-09-26T09:55:26Z")

</div>

对你这个需求，可以试试 Logjoint，可以自定义如何解析 log，并且从中提取特定的 field。

> **[GitHub - sergey-su/logjoint: LogJoint log viewer core. Viewer plugins for...](https://github.com/sergey-su/logjoint)**
>
> LogJoint log viewer core. Viewer plugins for publicly-available domains.

~~可惜的是这个软件对 CJK 的字符支持有问题，非拉丁字符都没法正常显示。已经向作者提了 issue，不过就不知道什么时候能修了。~~  
（更新：和开发者沟通后已经支持）

关于我自己的需求，依然没有找到比较合适的软件。有一个很旧的软件叫做 Kabikaboo，可以建立一个树结构，点击父节点会自动展示所有子节点的内容。不过这个软件 2012 年就停止更新了，现在也没有再更新过。

> **[Kabikaboo - Recursive Writing Assistant](https://sourceforge.net/projects/kabikaboo)**
>
> Download Kabikaboo - Recursive Writing Assistant for free. Kabikaboo is a simple tree-branch note organizer. It is meant to be used to help aid in the writing of a novel.

把多个文件合并成一个虚拟的文件，对应到现实中有两种应用场景，一种是同时查看多个 log，一种是写作的时候每个片段分开写，最后再拼起来。前者有 lnav，后者有 scrivener / latex，可惜对我的需求两种工具都不是很能满足。

> **[The Logfile Navigator](https://lnav.org/)**
>
> The Logfile Navigator, lnav for short, is an advanced log file viewer for the small-scale.

> **[\#1 Novel & Book Writing Software For Writers](https://www.literatureandlatte.com/scrivener/overview)**
>
> Discover the #1 novel & book writing software for writers! Streamline your writing process with powerful tools designed to help organize, edit, & bring your story to life.

更多讨论： [software rec - How can I edit multiple text files as one virtual document? - Super User](https://superuser.com/questions/600447/how-can-i-edit-multiple-text-files-as-one-virtual-document)

那既然现有的工具都没有，实在不行可能就得自己上手了。上文 Quicker 提供了一个不错的思路，不过我可能会希望不止能查看，还能直接编辑并应用回原始文件，以及可以提供大纲层级（年/月/日）。一开始想的是直接上 Python 直接拼一个 GUI 出来，后来发现 VS Code 有一个 [Virtual Document API](https://code.visualstudio.com/api/extension-guides/virtual-documents)，应该用起来更方便一些。然而这几天事情比较多，可能之后会尝试自己手搓一个吧。

---

<div class="post-metadata">

作者： ![jerrylus](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/jerrylus/32/14901_2.png) [@jerrylus](https://meta.appinn.net/u/jerrylus)\
发布日期： [2021 年9 月 26 日 10:19 UTC](https://meta.appinn.net/t/topic/26276/7 "2021-09-26T10:19:08Z")

</div>

一个小 Python 脚本，自动合并目录下的所有 `.txt` 文件到一个目标文件，顺序为创建时间升序。

```python
from pathlib import Path
from datetime import datetime

MEGRED_FILE_NAME = "merged.md"

def main():
    folder = Path(".")
    text_files = list(folder.glob("*.txt"))
    text_files.sort(key = lambda x: x.stat().st_ctime)
    with open(MEGRED_FILE_NAME, "w", encoding="utf8") as f:
        for t in text_files:
            if t.name == MEGRED_FILE_NAME:
                continue

            print(f"reading {t}")
            create_datetime = datetime.fromtimestamp(t.stat().st_ctime)
            f.write(f"# Filename = {t.name} | Creation = {create_datetime.strftime('%Y-%m-%d %H:%M:%S')} \n")
            with open(t, "r", encoding="utf8") as f2:
                f.writelines(f2.readlines())
            f.write("---EOF---\n")
    print("done")

if __name__ == " __main__":
    main()

```

---

<div class="post-metadata">

作者： ![xiaokonglong](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/xiaokonglong/32/908_2.png) [@xiaokonglong](https://meta.appinn.net/u/xiaokonglong)\
发布日期： [2021 年9 月 27 日 03:21 UTC](https://meta.appinn.net/t/topic/26276/8 "2021-09-27T03:21:01Z")

</div>

写个大样, 还挺好玩的.

```auto
private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();
            ofDialog.Multiselect = true;
            DialogResult dr= ofDialog.ShowDialog();
            if(dr==DialogResult.OK)
            {
                //FlowLayoutPanel flowLayoutPanel1 = new FlowLayoutPanel();
                foreach (String file in ofDialog.FileNames)
                {
                    
                    try
                    {
                        RichTextBox tb = new RichTextBox();
                        tb.LoadFile( file,RichTextBoxStreamType.PlainText);

                        tb.Width = flowLayoutPanel1.Width - 100;
                        flowLayoutPanel1.Controls.Add(tb);
                    }
                    
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }

            }

        }

```

 ![image](https://meta.appinn.net/uploads/default/original/3X/b/b/bb128c48713d14fc00ecf2243adf1f51c3698e6d.png)

没有排序, 细节你可以自己完善.

另外用ahk实现的话, 其实会更简单一些.

---

<div class="post-metadata">

作者： ![jerrylus](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/jerrylus/32/14901_2.png) [@jerrylus](https://meta.appinn.net/u/jerrylus)\
发布日期： [2021 年9 月 27 日 05:39 UTC](https://meta.appinn.net/t/topic/26276/9 "2021-09-27T05:39:19Z")

</div>

多谢！我原来打算就是用 Python 直接写一个类似于这样的，后来发现似乎虽然能写出来，但是界面感觉太古老了，因此还是考虑用 VS Code API 魔改了

---

<div class="post-metadata">

作者： ![Qingwa](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/qingwa/32/58632_2.png) [@Qingwa](https://meta.appinn.net/u/Qingwa)\
发布日期： [2021 年9 月 27 日 06:06 UTC](https://meta.appinn.net/t/topic/26276/10 "2021-09-27T06:06:55Z")

</div>

这太厉害了。
