Bug 42715

Summary: Directory.GetFiles & AllDirectories might fail
Product: [Mono] Class Libraries Reporter: Miha Markic <miha>
Component: mscorlibAssignee: Alexander Köplinger [MSFT] <alkpli>
Status: RESOLVED FIXED    
Severity: normal CC: bniemyjski, david, kumpera, masafa, mono-bugs+mono, Ryan.Melena
Priority: Normal    
Version: master   
Target Milestone: Future Release   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:

Description Miha Markic 2016-07-21 14:43:16 UTC
Consider this 
Directory.GetFiles("ROOT", "something/else/*", SearchOption.AllDirectories)

This method will most likely fail, since GetFiles try to apply search pattern to every subdirectory of root, 
i.e. it will try
ROOT/something/something/else/*, not just ROOT/something/else/*.

Actual behavior: DirectoryNotFound exception is thrown.
Expecting all subdirectories of ROOT/something/else/ are traversed, not those of ROOT/.

.net version works as expected.

Observed on Android, but I guess it is mono library issue.
Comment 1 Blake Niemyjski 2016-07-21 15:01:52 UTC
I'm also seeing this issue using our .NET Standard lib.
Comment 2 Rodrigo Kumpera 2016-07-23 00:14:38 UTC
Test case:

using System;
using System.IO;

class Foo { 
	static void Main () {
		try {
			if (Directory.Exists ("testdir"))
				Directory.Delete ("testdir", true); 
			Directory.CreateDirectory ("testdir");
			Directory.CreateDirectory ("testdir/something");
			Directory.CreateDirectory ("testdir/something/else");
			File.WriteAllText ("testdir/something/else/file", "hello");
			
			var r = Directory.GetFiles("testdir", "something/else/*", SearchOption.AllDirectories);
			Console.WriteLine (r.Length == 1);
			Console.WriteLine (r[0] == Path.Combine ("testdir", "something", "else", "file"));
			
		} finally {
			Directory.Delete ("testdir", true);
		}
	}
}
Comment 3 Alexander Köplinger [MSFT] 2016-11-29 15:42:16 UTC
*** Bug 31885 has been marked as a duplicate of this bug. ***
Comment 4 Alexander Köplinger [MSFT] 2016-11-29 16:06:45 UTC
Implemented a fix in https://github.com/mono/mono/pull/4042.
Comment 5 Alexander Köplinger [MSFT] 2016-12-02 00:15:29 UTC
The PR was merged.