【C#】对集合中的字段排序
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
private void startGetDir()
{
List
GetLocDirList(@"C:\test", LocFileList);
if (LocFileList != null)
{
//先对集合排序
LocFileList.Sort(delegate (ActFile x, ActFile y)
{
return y.time.CompareTo(x.time); //降序
//return x.time.CompareTo(y.time); //升序
});
foreach (ActFile se in FtpFileList)
{
if (se.name == "test.exe") { }
}
}
}
///
/// 获取当前目录下的目录及文件
///
/// param name="ftpfileList">
///
///
public void GetLocDirList(string dirName, List
{
//获取指定文件夹内的文件列表
DirectoryInfo d = new DirectoryInfo(dirName);
FileInfo[] files = d.GetFiles();//文件
DirectoryInfo[] directs = d.GetDirectories();//文件夹
foreach (FileInfo f in files)
{
localfileList.Add(new ActFile { isDir = false, name = f.Name, path = f.DirectoryName, level = 0, size = f.Length.ToString(), time = f.LastWriteTime, lineStr = "" }); //添加文件名到列表中
}
foreach (DirectoryInfo dd in directs)
{
localfileList.Add(new ActFile { isDir = true, name = dd.Name, path = dd.FullName, level = 0, size = "0", time = dd.LastWriteTime, lineStr = "" }); //添加目录名到列表中
GetLocDirList(dd.FullName, localfileList);
}
}
public class ActFile
{
public int level { get; set; } = 0;
public bool isDir { get; set; } = false;
public string name { get; set; } = "";
public string path { get; set; } = "";
public string size { get; set; } = "0";
public DateTime time { get; set; } = DateTime.Now;
public string lineStr { get; set; } = "";
}
该文章在 2021/9/3 15:15:08 编辑过 |
关键字查询
相关文章
正在查询... |