Skip to content

Instantly share code, notes, and snippets.

@AyrA
Last active October 30, 2017 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyrA/0f2621c1518ec054eae64e76dfbdbbb0 to your computer and use it in GitHub Desktop.
Save AyrA/0f2621c1518ec054eae64e76dfbdbbb0 to your computer and use it in GitHub Desktop.
Fast Windows search
@REM Creates a complete list of all files on all drives accessible right now.
@ECHO OFF
SETLOCAL
SET CACHEFILE=%TEMP%\FS_CACHE.txt
ECHO Creating Cache, please be patient...
IF EXIST "%CACHEFILE%" DEL "%CACHEFILE%"
FOR %%I IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
IF EXIST %%I:\NUL ECHO Scanning Drive %%I:\...
IF EXIST %%I:\NUL DIR %%I:\*.* /S /A /B>>"%CACHEFILE%"
)
ECHO Operation complete.
ENDLOCAL
PAUSE
@REM Searches live on disk without cache. Results are more accurate but searching is slower.
@ECHO OFF
SETLOCAL
SET /P SEARCH=Search:
ECHO Searching...
FOR %%I IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
IF EXIST %%I:\NUL DIR "%%I:\%SEARCH%" /S /A /B
)
ENDLOCAL
PAUSE
@REM Searches the cache generated by cache.bat for the given Search query
@ECHO OFF
SETLOCAL
SET CACHEFILE=%TEMP%\FS_CACHE.txt
IF NOT EXIST "%CACHEFILE%" GOTO NOTFOUND
SET /P SEARCH=Search:
ECHO Searching...
FIND /I "%SEARCH%" "%CACHEFILE%"
GOTO END
:NOTFOUND
ECHO The Cache does not exists. Use cache.bat to create.
GOTO END
:END
ENDLOCAL
PAUSE

Put the 3 batch files somewhere on your Desktop.

cache.bat

Use this to create/renew the cache. Depending on the number of files on your drives and the number of drives this might run for a few minutes.

If you prefer it would not index certain drives, remove the letters from the list.

search.bat

Use this to search for files. Enter test to find all files that contain test anywhere in the path. To find all Text files for example, enter .txt. This version doesn't supports wildcards

live_search.bat

This version is usually still faster than the Windows Search but slower than the cached search. It's live though and supports wildcards. Feel free to remove drive letters you don't want to search, or save multiple versions with different letter combinations. For local drives, Windows has a cache for the directory tree that is properly invalidated if the directory changes. If Subsequent searches feel faster than the first one it's not an illusion.

Caution

The search files allow you to enter a search query. Be aware that there is no escaping performed and the query is inserted into the command line "as-is". Simply put, do not enter ". It's an invalid file name character anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment