Atitit。Tree文件解析器的原理流程与设计实现 java c# php js
1.1. 判断目录 ,表示服 dirFlagChar = "└├─";1
1. 解析原理与流程
1.1. 判断目录 ,表示服 dirFlagChar = "└├─";
其中-类似于剑豪的制表符是表示目录的。。够好表示最后的目录,t制表符表示中间的目录。。
1.2. 剑豪制表符出现的位置与文件夹级别对应表
prefix |
lev1 |
2 |
1 |
5 |
2 |
6 |
2 |
9 |
3 |
12 |
4 |
13 |
4 |
16 |
5 |
17 |
5 |
20 |
6 |
21 |
6 |
24 |
7 |
27 |
8 |
28 |
8 |
作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://www.cnblogs.com/attilax/
1.3. 主要判读流程
if (level_curdir > level_lastdir)
lastDir = lastDir + "/" + curdirName;
else if(level_curdir==level_lastdir)
lastDir = getCurDirParent(level_curdir, lastDir) + "/"+curdirName;
else
lastDir = getCurDirParent(level_curdir, lastDir) + "/"
2. Tree结果
文件夹 PATH 列表
卷序列号为 802A-6864
C:.
│ .classpath
│ .mymetadata
│ .myumldata
│ .project
│ build.xml
│ myprocessdefinition1.xml
│ readme.txt
│ tree.txt
│
├─.settings
│ com.genuitec.eclipse.j2eedt.core.prefs
│
├─src
│ │ applicationContext-actions.xml
│ │ applicationContext-beans.xml
│ │ applicationContext-common.xml
│ │ hibernate.cfg.xml
│ │ init_datas.xml
│ │ jbpm.cfg.xml
│ │ log4j.properties
│ │ MessageResources.properties
│ │ test.java
3. Code----
public class TreeUtil {
private String encode;
private String path;
public TreeUtil(String p, String e) {
path = p;
encode = e;
}
public static String lastDir;
public static void main(String[] args) {
// TODO Auto-generated method stub
// 4>1,7>2,11>3,13>4
// dir 2>2, 5>3,9>4, 13>5 17>6 20>7
// countLengestFolderPath();
final String start = "c:\myoa";
String dirFlagChar = "└├─";
final String dirFlagChar1 = "─";
AFile f = new AFile("c:\myoa\tree.txt", "gbk");
final Set st = Sets.newConcurrentHashSet();
lastDir = "";
final DbStroreEngieen dbs = new DbStroreEngieen(pathx.webAppPath()
+ "/db/db1");
final List<Map> table = dbs.getTableRecs("dirLevel");
f.trave(new Closure<String, Object>() {
@Override
public Object execute(String line) throws Exception {
if (line.contains(dirFlagChar1)) {
int preIndex = line.indexOf(dirFlagChar1) + 1;
String curdirName = get_curdirName(preIndex, line);
if( curdirName.equals("com"))
System.out.println("dbg");
Map row = dbs.getRow(table, "prefix", preIndex);
int level_curdir = new ANum( row.get("lev1")).toInt();
int level_lastdir = get_level_curdir(lastDir);
if (level_curdir > level_lastdir) //src/com/zhaohui/oa/freemarker/templates
lastDir = lastDir + "/" + curdirName;
else if(level_curdir==level_lastdir)
lastDir = getCurDirParent(level_curdir, lastDir) + "/"+curdirName;
else
lastDir = getCurDirParent(level_curdir, lastDir) + "/"
+ curdirName;
lastDir= AString.LTrim(lastDir,"/");
st.add(preIndex);
String idex = new ANum(preIndex).toStr();
//System.out.println(idex + ":" + line);
System.out.println(lastDir);
}
return null;
}
//1 ".sett"
private String getCurDirParent(int level_curdir, String lastDir) {
String[] a = lastDir.split("/");
List<String> li = Lists.newArrayList();
for (int i = 0; i < level_curdir-1; i++) {
li.add(a[i]);
}
return com.attilax.collection.CollectionUtils.join(li, "/");
}
private String get_curdirName(int preIndex, String line) {
// TODO Auto-generated method stub
return line.substring(preIndex);
}
private int get_level_curdir(String lastDir) {
if(lastDir.equals("")) return 0;
String[] a = lastDir.split("/");
return a.length ;
}
});
List li = Lists.newArrayList();
li.addAll(st);
Collections.sort(li);
// List li2=
// from(li).orderby().exe();
// ACollections.set2list(st);
System.out.println(AtiJson.toJson(li));
System.out.println("--f");
}
4. 结果
.settings
src
dbg
src/com
src/com/zhaohui
src/com/zhaohui/oa
src/com/zhaohui/oa/freemarker
src/com/zhaohui/oa/freemarker/templates
src/com/zhaohui/oa/manager
src/com/zhaohui/oa/manager/impl
src/com/zhaohui/oa/model
src/com/zhaohui/oa/util
src/com/zhaohui/oa/web
src/com/zhaohui/oa/web/actions
src/com/zhaohui/oa/web/forms
test
Dbg
----end