Directory.GetFiles在每次使用时查找不同数量的文件

时间:2014-03-07 13:24:56

标签: c# c#-4.0

我刚碰到一堵砖墙,我想我可以帮忙。基本上,我有这个代码:

void DirSearch(string sDir)
        {
            try
            {
                    foreach (string d in Directory.GetDirectories(sDir))
                    {
                        foreach (string f in Directory.GetFiles(d, "*.JPG"))
                        {
                            // Start Creating Photo Objects and then adding them to the List
                            Image imageForPassing = new Bitmap(f);
                            Tuple<double, double> exifInfo = exifExtractor.ExtractCoordinates(imageForPassing);

                            if (exifInfo.Item1 != 0.0 && exifInfo.Item2 != 0.0)
                            {
                                var fileName = Path.GetFileName(f);

                                Photo photoObject = new Photo(fileName, exifInfo.Item1, exifInfo.Item2, f);
                                photosList.AddPhoto(photoObject);
                            }

                        }
                        DirSearch(d);
                    }
            }
            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.Message);
            }
        }

现在,这段代码的问题是我每次使用这段代码时都会找到所有文件。但是,有时它找不到所有文件,例如在48个现有文件中,它只找到25个。在另一个运行中,它将找到46个文件等。

任何想法,为什么会这样?

0 个答案:

没有答案