Bug 42715 - Directory.GetFiles & AllDirectories might fail
Summary: Directory.GetFiles & AllDirectories might fail
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: master
Hardware: PC Windows
: Normal normal
Target Milestone: Future Release
Assignee: Alexander Köplinger [MSFT]
URL:
: 31885 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-07-21 14:43 UTC by Miha Markic
Modified: 2016-12-02 00:15 UTC (History)
6 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

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.

Note You need to log in before you can comment on or make changes to this bug.