public ActionResult Test()
{
FileNodeTreeVm node = new FileNodeTreeVm();
string startFolder = @"E:\Rule_Release\rules";
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
if (!dir.Exists)
{
return View();
}
node.FullFileName = dir.FullName;
node.FileName = dir.Name;
node.CreationTime = dir.CreationTime;
NodeTree(node, dir);
NodeTreeFile(node, dir);
return View();
}
private void NodeTree(FileNodeTreeVm node, DirectoryInfo dir)
{
List<FileNodeTreeVm> nodeNextList = new List<FileNodeTreeVm>();
foreach (DirectoryInfo dirInfo in dir.GetDirectories())
{
FileNodeTreeVm nodeNext = new FileNodeTreeVm
{
FullFileName = dirInfo.FullName,
FileName = dirInfo.Name,
CreationTime = dirInfo.CreationTime,
};
NodeTree(nodeNext, new DirectoryInfo(dirInfo.FullName));
NodeTreeFile(nodeNext, dirInfo);
nodeNextList.Add(nodeNext);
}
node.Children.AddRange(nodeNextList);
}
private void NodeTreeFile(FileNodeTreeVm node, DirectoryInfo dir)
{
List<FileNodeTreeVm> nodeNextList = new List<FileNodeTreeVm>();
foreach (FileInfo fileInfo in dir.GetFiles())
{
FileNodeTreeVm nodeNext = new FileNodeTreeVm
{
FullFileName = fileInfo.FullName,
FileName = fileInfo.Name,
CreationTime = fileInfo.CreationTime,
Size = fileInfo.Length
};
nodeNextList.Add(nodeNext);
}
node.Children.AddRange(nodeNextList);
}
{
FileNodeTreeVm node = new FileNodeTreeVm();
string startFolder = @"E:\Rule_Release\rules";
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
if (!dir.Exists)
{
return View();
}
node.FullFileName = dir.FullName;
node.FileName = dir.Name;
node.CreationTime = dir.CreationTime;
NodeTree(node, dir);
NodeTreeFile(node, dir);
return View();
}
private void NodeTree(FileNodeTreeVm node, DirectoryInfo dir)
{
List<FileNodeTreeVm> nodeNextList = new List<FileNodeTreeVm>();
foreach (DirectoryInfo dirInfo in dir.GetDirectories())
{
FileNodeTreeVm nodeNext = new FileNodeTreeVm
{
FullFileName = dirInfo.FullName,
FileName = dirInfo.Name,
CreationTime = dirInfo.CreationTime,
};
NodeTree(nodeNext, new DirectoryInfo(dirInfo.FullName));
NodeTreeFile(nodeNext, dirInfo);
nodeNextList.Add(nodeNext);
}
node.Children.AddRange(nodeNextList);
}
private void NodeTreeFile(FileNodeTreeVm node, DirectoryInfo dir)
{
List<FileNodeTreeVm> nodeNextList = new List<FileNodeTreeVm>();
foreach (FileInfo fileInfo in dir.GetFiles())
{
FileNodeTreeVm nodeNext = new FileNodeTreeVm
{
FullFileName = fileInfo.FullName,
FileName = fileInfo.Name,
CreationTime = fileInfo.CreationTime,
Size = fileInfo.Length
};
nodeNextList.Add(nodeNext);
}
node.Children.AddRange(nodeNextList);
}