11.7 遍历目录下所有文件
递归遍历指定目录下的所有文件。
某小学在线教学终端调查表的汇总整理,统计各终端占比。
ID | STUDENT_NAME | TERMINAL |
---|---|---|
1 | Rebecca Moore | Phone |
2 | Ashley Wilson | Phone,PC,Pad |
3 | Rachel Johnson | Phone,PC,Pad |
4 | Emily Smith | PC,Pad |
5 | Ashley Smith | PC |
6 | Matthew Johnson | Phone |
7 | Alexis Smith | Phone,PC |
8 | Megan Wilson | Phone,PC,Pad |
… | … | … |
使用 directory@s() 函数递归查找文件。
脚本:
A | B | |
---|---|---|
1 | =directory@ps(“D:/Primary School”) | |
2 | >totalCount=0 | |
3 | for A1 | =T(A3) |
4 | =B3.conj(TERMINAL.split@c())|B4 | |
5 | >totalCount+=B3.len() | |
6 | =B4.groups(~:TERMINAL;count(~)/totalCount:PERCENTAGE) |
A1 递归遍历目录,列出所有文件
A2 定义变量 totalCount,用来存储总记录数
B3 循环导入各班级问卷 excel 文件
B4 将终端按逗号拆分后,合并到 B4 的序列中
B5 将每个班级人数加到 totalCount 中
A6 将 B4 的序列分组汇总,统计每个终端所占的百分比
运行结果:
A1:
Member |
---|
D:\Primary School\Grade1\Class1\Investigation.xlsx |
D:\Primary School\Grade1\Class2\Investigation.xlsx |
D:\Primary School\Grade1\Class3\Investigation.xlsx |
… |
B4:
Member |
---|
Phone |
Phone |
PC |
… |
A6:
TERMINAL | PERCENTAGE |
---|---|
PC | 0.7 |
Pad | 0.567 |
Phone | 0.933 |