111,129
社区成员
发帖
与我相关
我的任务
分享
var path = @"D:\File"
private void FindFilesInfo(string path)
{
foreach (string filePaht in Directory.GetFiles(path))
{
var file = new FileInfo(filePaht);
listFileInfo.Add(new CheckFileInfo { FileName = file.Name,Path = filePaht, FileEndTime = file.CreationTime});
}
foreach (string directory in Directory.GetDirectories(path))
{
FindFilesInfo(directory);
}
}
listFileInfo.Add(new CheckFileInfo { FileName = file.Name,Path = "path的相对路径", FileEndTime = file.CreationTime});
我写的可是rootPath,不是path。。。。
private void FindFilesInfo(string path, string rootPath = null)
{
if(rootPath == null) rootPath = path;
....
FindFilesInfo(directory, rootPath);
}
var path = @"D:\File"
var FindPath = "*-*-*-*-*-*-*-*";
private void FindFilesInfo(string path)
{
if (path.IndexOf(FindPath) < 0) { FindPath = path; }
foreach (string filePaht in Directory.GetFiles(path))
{
var fileInfo = new FileInfo(filePaht);
listFileInfo.Add(new CheckFileInfo { FileName = fileInfo.Name,Path = filePaht.Substring(FindPath.Length), FileEndTime = fileInfo.CreationTime});
}
foreach (string directory in Directory.GetDirectories(path))
{
FindFilesInfo(directory);
}
}
filePaht = filePaht.SubString(rootPath.Length);filePaht.SubString(0, rootPath.Length);