@@ -68,7 +68,9 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
6868
6969 IAsyncEnumerable < SearchResult > searchResults ;
7070
71- bool isPathSearch = query . Search . IsLocationPathString ( ) || IsEnvironmentVariableSearch ( query . Search ) ;
71+ bool isPathSearch = query . Search . IsLocationPathString ( )
72+ || EnvironmentVariables . IsEnvironmentVariableSearch ( query . Search )
73+ || EnvironmentVariables . HasEnvironmentVar ( query . Search ) ;
7274
7375 string engineName ;
7476
@@ -178,16 +180,16 @@ private async Task<List<Result>> PathSearchAsync(Query query, CancellationToken
178180
179181 // Query is a location path with a full environment variable, eg. %appdata%\somefolder\, c:\users\%USERNAME%\downloads
180182 var needToExpand = EnvironmentVariables . HasEnvironmentVar ( querySearch ) ;
181- var locationPath = needToExpand ? Environment . ExpandEnvironmentVariables ( querySearch ) : querySearch ;
183+ var path = needToExpand ? Environment . ExpandEnvironmentVariables ( querySearch ) : querySearch ;
182184
183185 // Check that actual location exists, otherwise directory search will throw directory not found exception
184- if ( ! FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( locationPath ) . LocationExists ( ) )
186+ if ( ! FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( path ) . LocationExists ( ) )
185187 return results . ToList ( ) ;
186188
187189 var useIndexSearch = Settings . IndexSearchEngine is Settings . IndexSearchEngineOption . WindowsIndex
188- && UseWindowsIndexForDirectorySearch ( locationPath ) ;
190+ && UseWindowsIndexForDirectorySearch ( path ) ;
189191
190- var retrievedDirectoryPath = FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( locationPath ) ;
192+ var retrievedDirectoryPath = FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( path ) ;
191193
192194 results . Add ( retrievedDirectoryPath . EndsWith ( ":\\ " )
193195 ? ResultManager . CreateDriveSpaceDisplayResult ( retrievedDirectoryPath , query . ActionKeyword , useIndexSearch )
@@ -198,21 +200,21 @@ private async Task<List<Result>> PathSearchAsync(Query query, CancellationToken
198200
199201 IAsyncEnumerable < SearchResult > directoryResult ;
200202
201- var recursiveIndicatorIndex = query . Search . IndexOf ( '>' ) ;
203+ var recursiveIndicatorIndex = path . IndexOf ( '>' ) ;
202204
203205 if ( recursiveIndicatorIndex > 0 && Settings . PathEnumerationEngine != Settings . PathEnumerationEngineOption . DirectEnumeration )
204206 {
205207 directoryResult =
206208 Settings . PathEnumerator . EnumerateAsync (
207- query . Search [ ..recursiveIndicatorIndex ] . Trim ( ) ,
208- query . Search [ ( recursiveIndicatorIndex + 1 ) ..] ,
209+ path [ ..recursiveIndicatorIndex ] . Trim ( ) ,
210+ path [ ( recursiveIndicatorIndex + 1 ) ..] ,
209211 true ,
210212 token ) ;
211213
212214 }
213215 else
214216 {
215- directoryResult = DirectoryInfoSearch . TopLevelDirectorySearch ( query , query . Search , token ) . ToAsyncEnumerable ( ) ;
217+ directoryResult = DirectoryInfoSearch . TopLevelDirectorySearch ( query , path , token ) . ToAsyncEnumerable ( ) ;
216218 }
217219
218220 if ( token . IsCancellationRequested )
@@ -245,12 +247,5 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
245247 x => FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( pathToDirectory ) . StartsWith ( x . Path , StringComparison . OrdinalIgnoreCase ) )
246248 && WindowsIndex . WindowsIndex . PathIsIndexed ( pathToDirectory ) ;
247249 }
248-
249- internal static bool IsEnvironmentVariableSearch ( string search )
250- {
251- return search . StartsWith ( "%" )
252- && search != "%%"
253- && ! search . Contains ( '\\ ' ) ;
254- }
255250 }
256251}
0 commit comments