private static string [] GetFileSystemEntries(string path, string searchPattern, FileAttributes mask, FileAttributes attrs) { if (searchPattern == null) { throw new ArgumentNullException("searchPattern"); } if (searchPattern.Length == 0) { return new string [] {} } ; bool stop; string path_with_pattern = ValidateDirectoryListing(path, searchPattern, out stop); if (stop) { return new string [] { path_with_pattern } } ; MonoIOError error; string [] result = MonoIO.GetFileSystemEntries(path, path_with_pattern, (int)attrs, (int)mask, out error); if (error != 0) { throw MonoIO.GetException(Path.GetDirectoryName(Path.Combine(path, searchPattern)), error); } return(result); }
private static string [] GetFileSystemEntries(string path, string searchPattern, FileAttributes mask, FileAttributes attrs) { if (path == null || searchPattern == null) { throw new ArgumentNullException(); } if (searchPattern.Length == 0) { return new string [] {} } ; if (path.Trim().Length == 0) { throw new ArgumentException("The Path does not have a valid format"); } string wild = Path.Combine(path, searchPattern); string wildpath = Path.GetDirectoryName(wild); if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Path contains invalid characters"); } if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1) { if (path.IndexOfAny(SearchPattern.InvalidChars) == -1) { throw new ArgumentException("Path contains invalid characters", "path"); } throw new ArgumentException("Pattern contains invalid characters", "pattern"); } MonoIOError error; if (!MonoIO.ExistsDirectory(wildpath, out error)) { if (error == MonoIOError.ERROR_SUCCESS) { MonoIOError file_error; if (MonoIO.ExistsFile(wildpath, out file_error)) { return(new string [] { wildpath }); } } if (error != MonoIOError.ERROR_PATH_NOT_FOUND) { throw MonoIO.GetException(wildpath, error); } if (wildpath.IndexOfAny(SearchPattern.WildcardChars) == -1) { throw new DirectoryNotFoundException("Directory '" + wildpath + "' not found."); } if (path.IndexOfAny(SearchPattern.WildcardChars) == -1) { throw new ArgumentException("Pattern is invalid", "searchPattern"); } throw new ArgumentException("Path is invalid", "path"); } string path_with_pattern = Path.Combine(wildpath, searchPattern); string [] result = MonoIO.GetFileSystemEntries(path, path_with_pattern, (int)attrs, (int)mask, out error); if (error != 0) { throw MonoIO.GetException(wildpath, error); } return(result); }