当前位置:网站首页>文件结构树
文件结构树
2022-08-06 14:31:00 【张春成】
文件结构树
现代计算机操作系统往往会用目录树的结构来维护用户的文件。
但用户面对这个树形的结构往往需要四处翻找,才能找到他想要的文件。
因此,本文尝试用交互式圆饼图展示文件结构,力图用最简洁的方式来帮助用户找到他需要的文件。
目录树结构可视化
使用 Javascript 搭建前端可视化环境,实现代码可见
Data structure of my WeChat articles[1]
它将目录结构表示成一个圆圈,圆圈上的块代表目录节点,点击这些节点可以跳转到该子目录中。
这种做法的好处是可以方便地看到这一级和下一级目录,并且目录块所占的区域面积正比于它所含有的文件数量。
因为在使用电脑的过程中,如果单纯地找某个文件可能是比较困难的,困难有条
首先,人眼对长串的目录名其实不是很敏感,分辨这些文件名称对于疲劳的打工人来说,往往是场灾难; 其次,目录中的文件往往与目录名并没有很强的偶合关系,这就导致上面的灾难其实是无用功; 再次,对于特定的文件来说,如果能够早一步看到与它相邻的文件名,那么就会提前唤醒大脑中的注意机制,它就会显得好找一些; 另外,目录的大小也对寻找文件起着重要作用,这是因为人的记忆机制往往会通过额外的信息来更高效地存储和检索特定信息。这就像是背古诗,知道前一句背后一句很容易;但知道后一句背前一句则很难; 最后,以上四条是我刚编的,完全没经过大脑,我做这个只是觉得这个方法有点好看。




目录树的遍历代码
这是一段切实可用的递归代码,它之所以出现在这里是出于 2 点考虑,
首先,它有点用,至少它是能够正常(安全)工作的递归方法; 其次,它没有那么有用,还不值得单独传到 GITHUB 上。
# %%
import os
import json
from pathlib import Path
# %%
# Where to dig
root_path = Path(os.environ['HOME'], 'onedrive', 'laptop', 'WritingScripts')
root_path
# %%
# Check whether the path is ignored
def _check(path):
'''Check the [path] for its validity'''
if path.name.startswith('.'):
return False
return True
def _iter(node, folder, depth):
'''
Iter function for digging into the folder.
Args:
- node: Where the results are added;
- folder: The folder to start with;
- depth: A number controls when the iteration stops, it stops when it down below 0.
'''
if depth < 0:
return
depth -= 1
if not folder.is_dir():
return
for sub in folder.iterdir():
if not _check(sub):
continue
node['children'].append(dict(name=sub.name, children=[]))
_iter(node['children'][-1], sub, depth)
if len(node['children'][-1]['children']) == 0:
node['children'][-1].pop('children')
node['children'][-1]['value'] = 1
return
# %%
# Dig into root_folder and the results are restored into the data
data = dict(name=root_path.name, children=[])
_iter(data, root_path, depth=3)
# %%
# Save the data into data.json
json.dump(data, open('data.json', 'w'))
# %%
参考资料
Data structure of my WeChat articles: https://observablehq.com/@listenzcc/data-structure-of-my-wechat-articles
边栏推荐
猜你喜欢

redis使用

Odoo website tutorial - theme
![[Installation filling pit] -import win32api, sys, os ImportError: DLL load failed: The specified module could not be found.](/img/33/7f66bcf72499729078b5546f3464e1.png)
[Installation filling pit] -import win32api, sys, os ImportError: DLL load failed: The specified module could not be found.

听声辨物,这是AI视觉该干的???|ECCV 2022

Machine learning notes (Wu En up to the teacher)

15天入门Web3,从0到1速成指南

接口测试CURL复制以及postman的Code功能

DC-9--vulnhub range

JS柯里化

LeetCode Brushing Diary: 899. Ordered Queue
随机推荐
【ASM】字节码操作 MethodVisitor 案例实战 init 方法生成
[Numpy] Solution: About the meaning and pits of dtype=object
ETCD 入门
[MySQL - Transaction] Four Features and Isolation Levels
论文解读:《DeepKla:一种基于注意力机制的深度神经网络,用于蛋白质赖氨酸乳酸化位点预测》
挖财股票开户安全吗?怎么开账户是安全可靠的?
leetcode经典例题——滑动窗口最大值
R语言ggplot2可视化:可视化多分类变量箱图(Box Plot)、自定义箱图箱体的填充色、添加主标题、副标题、题注信息
浅谈树状数组
The basic process used by mosquitto and some problems encountered
互斥锁 try_lock 自旋锁 读写锁 原子操作 共享内存
听声辨物,这是AI视觉该干的???|ECCV 2022
20220804-al422 test 01
传奇开服教程:传奇无限制仓库脚本分享
读《架构师修炼之道》有感
Interface test CURL replication and postman's Code function
消息队列系列
typeindex类型支持库学习
ERC4907 的到来 会给 NFT 带来哪些变革?
豪威宣布发布世界首款产品级 CIS / EVS 融合视觉芯片