Question : directoryInfo.GetFiles() is slow in .net.

We are using provided piece of code.
When we did the performance testing we found that this piece of code is taking 12 sec for less then 10 files over the network.
I am little confused, why it is taking this huge amount of time for such small number of files. Is there any issue of bandwidth or Is there a better way to do the same thing?

I am using following code in one of our project:

private bool outputfileNameExists(string fileName,string regionName)
        {
            fileName = formatOutputFileName(fileName);
            DirectoryInfo directoryInfo = new DirectoryInfo(ConfigurationManager.
                        AppSettings["ReportDownLoadPath"].Replace("Region", regionName).Trim());
            FileInfo[] fileInfo;
            //If directory exists in the specified drive
            if (directoryInfo.Exists)
            {
                fileInfo = directoryInfo.GetFiles();
                //If files are available in the specified folder
                if (fileInfo.Length > 0)
                {
                    char[] fileSplitter = ConfigurationManager.AppSettings["FileSplitter"].ToCharArray();
                    for (int fileIndex = 0; fileIndex < fileInfo.Length; fileIndex++)
                    {
                        if (fileInfo[fileIndex].FullName.Split(fileSplitter)[0].Trim().Contains(fileName.Trim()))
                        {
                            return true;
                        }
                    }
                }  
            }
            return false;
        }
Looking forward to hearing from you.

Answer : directoryInfo.GetFiles() is slow in .net.

Not that I am aware of. I have never noticed any leaks on the projects it was used.
These projects were applications which ran fairly short, so memory leaks would go unnoticed most of the time.

Regards
Marco

Random Solutions  
 
programming4us programming4us