pedrotainha / csharptest-net

Automatically exported from code.google.com/p/csharptest-net
0 stars 0 forks source link

FindFile doesn't seem to recurse directories properly when a filter other than "*" or "*.*" is specified #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
As above really.

Just tried your sample code with 

var fcounter = new CSharpTest.Net.IO.FindFile(@"F:\", "*.docx", true, true, 
true);

and

var fcounter = new CSharpTest.Net.IO.FindFile(@"F:\", "*.cs", true, true, true);

The former returned the 2 that were in the root but there are 23 according to 
"dir *.docx /s"

The latter returned 0 files when there are 53k+!

Looks like this code is returning without checking any other folders....
(after call to FindFirstFileEx)
            if ((IntPtr.Size == 4 && hFile.ToInt32() == -1) ||
                (IntPtr.Size == 8 && hFile.ToInt64() == -1L))
            {
                Win32Error(Marshal.GetLastWin32Error());
                return;
            }

Just tried commenting it out and I'm getting the same results as dir /s

Original issue reported on code.google.com by simon.he...@simmotech.co.uk on 10 Feb 2013 at 1:06

GoogleCodeExporter commented 8 years ago
Interesting...  
Searching in the TestFindFile's sample directory:

            File.WriteAllText(Path.Combine(TestFolder, "a.1"), "a");
            File.WriteAllText(Path.Combine(TestFolder, "b.2"), "b");
            File.WriteAllText(Path.Combine(TestFolder, "c.3"), "c");
            Directory.CreateDirectory(Path.Combine(TestFolder, "child1"));
            File.WriteAllText(Path.Combine(TestFolder, @"child1\a.1"), "a");
            File.WriteAllText(Path.Combine(TestFolder, @"child1\b.2"), "b");
            File.WriteAllText(Path.Combine(TestFolder, @"child1\c.3"), "c");
            Directory.CreateDirectory(Path.Combine(TestFolder, @"child1\child2"));

I tried to replicate this result with the following unit test:

        [Test]
        public void TestFilesByExtension()
        {
            int files = 0;
            string dir = TestFolder;

            var ff = new FindFile(dir, "*.2", true, true, true);
            ff.FileFound += (sender, args) => { files++; };
            ff.Find();
            Assert.AreEqual(2, files);
        }

This test is passing.  I'm not sure how to replicate the failure you 
experienced.  Can you help me build a unit test that exhibits the behavior you 
are describing?

Original comment by Grig...@gmail.com on 26 Jan 2014 at 7:17