views:

23

answers:

1

As the title suggests, I'm looking for a way to get attributes of a large number of files in a directory, but without adding the cost of an additional disk access for each file.

For example, if I get the Name attribute of FileInfo objects in a collection, then there is no additional disk access. However if I get the LastWriteTimeUtc, then an additional disk access is made.

My code:

DirectoryInfo di = new DirectoryInfo(myDir);
FileInfo[] allFiles = di.GetFiles("*.*", SearchOption.TopDirectoryOnly);
foreach (FileInfo fInfo in allFiles)
{
    name = fInfo.Name  //no additional disk access made
    lastMod = fInfo.LastWriteTimeUtc  //further disk access made!!!
}

Does anyone know of a way I can get this information in one round trip? I would have hoped that DirectoryInfo.GetFiles() does this but no luck.

Thanks in advance.

A: 

If you really care about this, you should probably write this in C using FindFirstFile/GetFileTime, etc.

Paul Betts