@@ -146,14 +146,10 @@ private static List<string> FindAlternativePaths (string fileName, string projec
146146
147147 // Also check subdirectories (one level deep)
148148 var subdirs = Directory . GetDirectories ( projectDir ) ;
149- foreach ( var subdir in subdirs )
150- {
151- var subdirCandidate = Path . Join ( subdir , baseName ) ;
152- if ( File . Exists ( subdirCandidate ) )
153- {
154- alternatives . Add ( subdirCandidate ) ;
155- }
156- }
149+ alternatives . AddRange (
150+ subdirs
151+ . Select ( subdir => Path . Join ( subdir , baseName ) )
152+ . Where ( File . Exists ) ) ;
157153 }
158154 }
159155 catch ( Exception ex ) when ( ex is ArgumentException or
@@ -181,10 +177,10 @@ UnauthorizedAccessException or
181177 }
182178 }
183179 catch ( Exception ex ) when ( ex is ArgumentException or
184- ArgumentNullException or
185- PathTooLongException or
186- UnauthorizedAccessException or
187- IOException )
180+ ArgumentNullException or
181+ PathTooLongException or
182+ UnauthorizedAccessException or
183+ IOException )
188184 {
189185 // Ignore errors when searching in Documents folder
190186 }
@@ -203,23 +199,20 @@ UnauthorizedAccessException or
203199 var originalDrive = Path . GetPathRoot ( fileName ) ? [ 0 ] ;
204200 var pathWithoutDrive = fileName . Length > 3 ? fileName [ 3 ..] : string . Empty ;
205201
206- foreach ( var drive in driveLetters )
202+ foreach ( var drive in driveLetters . Where ( drive => drive != originalDrive && ! string . IsNullOrEmpty ( pathWithoutDrive ) ) )
207203 {
208- if ( drive != originalDrive && ! string . IsNullOrEmpty ( pathWithoutDrive ) )
204+ var alternatePath = $ "{ drive } :\\ { pathWithoutDrive } ";
205+ if ( File . Exists ( alternatePath ) && ! alternatives . Contains ( alternatePath ) )
209206 {
210- var alternatePath = $ "{ drive } :\\ { pathWithoutDrive } ";
211- if ( File . Exists ( alternatePath ) && ! alternatives . Contains ( alternatePath ) )
212- {
213- alternatives . Add ( alternatePath ) ;
214- }
207+ alternatives . Add ( alternatePath ) ;
215208 }
216209 }
217210 }
218211 catch ( Exception ex ) when ( ex is ArgumentException or
219- ArgumentNullException or
220- PathTooLongException or
221- UnauthorizedAccessException or
222- IOException )
212+ ArgumentNullException or
213+ PathTooLongException or
214+ UnauthorizedAccessException or
215+ IOException )
223216 {
224217 // Ignore errors when searching on different drives
225218 }
0 commit comments