C# 遍历指定目录下的所有文件及文件夹以及遍历数据库的方法

时间:2023-03-10 01:06:59
C# 遍历指定目录下的所有文件及文件夹以及遍历数据库的方法
// DirectoryInfo di = new DirectoryInfo(@"D:\Test");
// FindFile(di);
static void FindFile(DirectoryInfo di)
{
  FileInfo[] fis = di.GetFiles();
  for (int i = ; i < fis.Length; i++)
  {
    Console.WriteLine("文件:" + fis[i].FullName);
  }
  DirectoryInfo[] dis = di.GetDirectories();
  for (int j = ; j < dis.Length; j++)
  {
    Console.WriteLine("目录:" + dis[j].FullName);
    FindFile(dis[j]);
  }
}

根据父级遍历全部数据

       BaseOrganizeManager organizeManager = new BaseOrganizeManager();
int count = ;
JsonResult<string> reult = null;
void FindChild(List<BaseOrganizeEntity> organizeEntities)
{
foreach (var item in organizeEntities)
{
if (item.Enabled == || item.DeletionStateCode == )
{
continue;
}
reult = CaiNiaoAPIUtilities.SyncOrganizeToCaiNiao(item);
System.Console.WriteLine(count + ",执行同步:" + item.FullName + "," + DateTime.Now);
System.Console.WriteLine("返回" + reult.Data + "," + DateTime.Now);
count++; }
List<BaseOrganizeEntity> organizeChids = null;
string where = string.Empty;
foreach (var item in organizeEntities)
{
where = BaseOrganizeEntity.FieldParentId + " = '" + item.Id + "' ";
organizeChids = organizeManager.GetList<BaseOrganizeEntity>(where);
FindChild(organizeChids);
}
}
            string where = BaseOrganizeEntity.FieldParentId + " IS NULL ";
List<BaseOrganizeEntity> organizeEntities = organizeManager.GetList<BaseOrganizeEntity>(where);
FindChild(organizeEntities);