1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using QM.KJGH.Model;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using WS.IO;
- namespace QM.KJGH.CGGL
- {
- public static class FileHelp
- {
- #region
- /// <summary>
- /// 获取目录文件
- /// </summary>
- /// <param name="rootpath">根目录</param>
- /// <returns></returns>
- public static List<Tree> FileCatalog(string rootpath) {
- List<Tree> trees = new List<Tree>();
- if (!Directory.Exists(rootpath))
- return trees;
- ForDirectory(rootpath, trees);
- return trees;
- }
- private static void ForDirectory(string path, List<Tree> trees)
- {
- var dirs = Directory.GetDirectories(path);
- foreach (var item in dirs)
- {
- var ptree = new Tree
- {
- label = Path.GetFileName(item),
- value = Path.GetFileName(item),
- };
- if (item.EndsWith(".gdb"))
- {
- ptree.IsParent = false;
- ptree.Add = FileManage.Instance.ToRelativePath(item);
- }
- else
- {
- ptree.IsParent = true;
- ptree.children = new List<Tree>();
- ForDirectory(item, ptree.children);
- }
- trees.Add(ptree);
- }
- trees.AddRange(Directory.GetFiles(path).Select(f => {
- return new Tree
- {
- label = Path.GetFileName(f),
- value = Path.GetFileName(f),
- IsParent = false,
- Add = FileManage.Instance.ToRelativePath(f)
- };
- }));
- }
- #endregion
- }
- }
|