首页 > 代码库 > 通过数据库数据构建文件夹结构的递归算法
通过数据库数据构建文件夹结构的递归算法
public void fileRecursion(List<RFN.BM.OA.NetdiskDataInfo> netdiskDataInfoRecursions, string path)
{
var uploadFile = new NST.BL.STM.UploadFile();
var netdiskData = http://www.mamicode.com/new RFN.BL.OA.NetdiskData();
foreach (var netdiskDataInfoRecursion in netdiskDataInfoRecursions)
{
if (netdiskDataInfoRecursion.FileSize == null)//通过FileSize 判断是文件还是文件夹
{
var pathDirectory = path + netdiskDataInfoRecursion.DataName + "\\";
Directory.CreateDirectory(pathDirectory);//建立文件夹
}
else
{
string filePath = path + netdiskDataInfoRecursion.DataName;
var uploadFileInfo = uploadFile.SelectById(netdiskDataInfoRecursion.UploadFileId);
string uploadFilePath = @"D:\Work\Work4\RFNWeb\Uploads\" + uploadFileInfo.NewFileName;//本地Uploads路径
FileInfo filePathInfo = new FileInfo(filePath);
FileInfo uploadFilePathInfo = new FileInfo(uploadFilePath);
var filePathCreate = filePathInfo.Create();
filePathCreate.Close();
uploadFilePathInfo.CopyTo(filePath, true);//从上传文件中复制到建立好的文件夹中
}
}
foreach (var netdiskRecursion in netdiskDataInfoRecursions)
{
if (netdiskRecursion.FileSize == null)
{
netdiskDataInfoRecursions = netdiskData.SelectBy("[ParentId]=?", "[CreateTime]", netdiskRecursion.Id);
if (netdiskDataInfoRecursions != null)
{
path = path + netdiskRecursion.DataName + "\\";
fileRecursion(netdiskDataInfoRecursions, path);//如果是文件夹且数据不为空,则继续调用此方法。
}
}
}
}
通过数据库数据构建文件夹结构的递归算法