Find & Search Inside Files
Microsoft File Explorer search functions are limited to a few file types. What other options are available?
MS File Explorer – Expanding it’s Limited Default Capabilities
By default 10 File Explorer will only search for text inside a limited set of file extensions (a.k.a. file types).
The Indexing Options feature in Windows Control Panel can be set to add search support of additional file extensions.
The default supported file types include TXT files, DOCX files, LOG files, XLSX files.
DOS findstr
Command
In a Windows Command prompt, the findstr
command searches the current directory (in this case C:\) and all subdirectories for the pattern “COMMIT” in any file with a .cs extension and outputs only the filename.
C:\>findstr /s /m "COMMIT" *.cs
For more, see: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/findstr
PowerShell
Search Current Directory
Searchs the current path for .bat
files contain the string "Monthly
".
Select-String -Path "*.bat" -SimpleMatch -Pattern "Monthly"
Select-String -Path "*.bat" "Monthly"
-SimpleMatch uses a simple match rather than a regular expression match.
In a simple match,Select-String
searches the input for the text in the Pattern parameter. It doesn't interpret the value of the Pattern parameter as a regular expression statement.
Default search type is a regular expression search.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7.3
Recursive Search
The PowerShell command below searches the current directory (in this case C:\) and all subdirectories for .cs
files containing text with the pattern "COMMIT" and lists the filenames.
PS C:\>Get-ChildItem -Path "*.cs" -Recurse | Select-String "COMMIT" -List | Select Path
For more, see: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-5.1
NotePad++
Notepad++ is a widely used and well recommended, open source text editor. Notepad++ can be installed as a stand-alone .exe file. Notepad++ (notepad-plus-plus.org)
Syntax highlighting is supported OOTB for many languages.
Comparing two files. Diff type functions are available as plugins:
Plugins - includes a Plugin Admin to download and management plugins.
It’s Find in Files search function will search all files in given folders.
Notepad++ Find in Files
Search > Find in Files… (Ctrl + Shift + F)