I have some old code that was written to support work on a local network, but now may be run by remote workers. Individual file system accesses that were reasonably fast on the local network are intolerably slow for remote access because of all the additional overhead.
For reading files, I have been able to improve speed greatly by reading the entire file into a string as a single access and replacing the StreamReader used to process it with StringReader instead. But searching the file system for possible file paths is a bit trickier.
There is a particular directory (the "master") which contains many subdirectories. Some of these subdirectories (the "models") have a subdirectory ("current") and a file (the "kompdef") in that subdirectory which contains information pertinent to the model. There are many other directories in the master which do not have a kompdef file and thus are not models, and the model directories themselves will have many other directories than "current" (some of which may have komdef files that I do not care about). I have a form with a drop-down that lists the models for the user's selection. Creating the list of models to populate the drop-down is done with the following code:
//KompdefTail = @"current\komdef" (it's in a Unix file system, so no extention)
List<string> ModelNames = new List<string>();
foreach (DirectoryInfo Model in (new DirectoryInfo(MasterPath)).GetDirectories())
{
if ((new FileInfo(Model.FullName + KompdefTail)).Exists)
{
ModelNames.Add(Model.Name);
}
}
However this requires many file system accesses, which means the form takes around 30 seconds to load up remotely, even though it takes less than 1 second on-site.
Is there some way I can get a list of paths of the form:
- masterpath\*\kompdeftail
where masterpath and kompdeftail are known, with a minimal number of file system accesses?