···160161 // Recursively walk into subdirectories
162 if metadata.file_type == VfsFileType::Directory {
163- // Continue if: recursive pattern, or we haven't reached max depth, or pattern has more components
000000000164 let should_recurse = is_recursive
165- || current_depth < max_depth
166- || (normalized_pattern.contains('/')
167- && current_depth < normalized_pattern.split('/').count());
168169 if should_recurse {
170 walk_directory(
···160161 // Recursively walk into subdirectories
162 if metadata.file_type == VfsFileType::Directory {
163+ // Only recurse if:
164+ // 1. Pattern contains ** (recursive wildcard), OR
165+ // 2. Pattern has path separators and we haven't matched all components yet
166+ let has_path_separator = normalized_pattern.contains('/');
167+ let pattern_component_count = if has_path_separator {
168+ normalized_pattern.split('/').count()
169+ } else {
170+ 1
171+ };
172+173 let should_recurse = is_recursive
174+ || (has_path_separator && current_depth + 1 < pattern_component_count);
00175176 if should_recurse {
177 walk_directory(