【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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |