我在.NET中編寫目錄掃描器。對(duì)于每個(gè)文件/目錄,我需要以下信息。 class Info { public bool IsDirectory; public string Path; public DateTime ModifiedDate; public DateTime CreatedDate; }我有這個(gè)功能: static List<Info> RecursiveMovieFolderScan(string path){ var info = new List<Info>(); var dirInfo = new DirectoryInfo(path); foreach (var dir in dirInfo.GetDirectories()) { info.Add(new Info() { IsDirectory = true, CreatedDate = dir.CreationTimeUtc, ModifiedDate = dir.LastWriteTimeUtc, Path = dir.FullName }); info.AddRange(RecursiveMovieFolderScan(dir.FullName)); } foreach (var file in dirInfo.GetFiles()) { info.Add(new Info() { IsDirectory = false, CreatedDate = file.CreationTimeUtc, ModifiedDate = file.LastWriteTimeUtc, Path = file.FullName }); } return info; }事實(shí)證明這種實(shí)現(xiàn)是相當(dāng)緩慢的。有什么辦法可以加快速度嗎?我正在考慮使用FindFirstFileW進(jìn)行手動(dòng)編碼,但是如果有一種內(nèi)置的方法可以更快地避免這種情況,我想避免這種情況。
- 3 回答
- 0 關(guān)注
- 529 瀏覽
添加回答
舉報(bào)
0/150
提交
取消