To search inside Windows batch files for a command or phrase, run this in Command Prompt:
findstr /s /i /n /l /c:"your string" "C:Scripts*.bat" "C:Scripts*.cmd"
In PowerShell, use:
Get-ChildItem "C:Scripts" -Recurse -File -Include *.bat,*.cmd |
Select-String -SimpleMatch -Pattern "your string"
These commands search the contents of .bat and .cmd files. If you only need to locate batch files by filename, use where /r or Get-ChildItem instead.
As an Amazon Associate I earn from qualifying purchases.
First decide whether you need filenames or file contents
“Find a batch file” can mean two different things:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errors- Find files by name: locate files ending in
.bator.cmd. - Search file contents: find scripts containing a command, variable, phrase, or command-line string.
The commands below keep those tasks separate. Windows batch scripts commonly use both extensions, so searching only for *.bat can miss valid command scripts.
#1 Best Overall
Find batch files by filename
In Command Prompt:
where /r "C:Scripts" *.bat
where /r "C:Scripts" *.cmd
In PowerShell:
Get-ChildItem -Path "C:Scripts" -Recurse -File -Include *.bat,*.cmd
In Windows Explorer, enter *.bat OR *.cmd in the search box. Filename searches locate scripts; they do not inspect the text inside them.
Search batch-file contents with Command Prompt
Microsoft’s built-in findstr searches text in the files specified by your filename patterns.
findstr /s /i /n /l /c:"ipconfig /all" "C:Scripts*.bat" "C:Scripts*.cmd"
The switches mean:
/ssearches the specified directory and its subdirectories./iignores letter case./ndisplays line numbers./ltreats the search term as literal text instead of a regular expression./c:keeps a phrase containing spaces together as one search string.
A match may look like this:
C:Scriptsnetwork.bat:14:ipconfig /all
That output gives the path, line number, and matching line.
Search the current directory and its subdirectories
If Command Prompt is already open in the directory you want to scan, you can shorten the command:
findstr /s /i /n /l /c:"ipconfig /all" *.bat *.cmd
List only files that contain a match
Add /m when you want an inventory of matching files rather than every matching line:
findstr /s /i /m /l /c:"ipconfig /all" "C:Scripts*.bat" "C:Scripts*.cmd"
Search every file type
To search text files beyond batch scripts, use a broader filename mask:
findstr /s /i /n /l /c:"ipconfig /all" "C:Scripts*.*"
This may inspect logs, configuration files, source code, and unsuitable binary files. Restricting the search to known text extensions is usually faster and produces more useful results.
Search for regular-expression patterns
Without /l, findstr uses its own limited regular-expression syntax. For example:
findstr /s /i /r /n "set .* PATH" "C:Scripts*.bat"
Microsoft documents constructs including ., *, ^, $, character classes, and word-boundary forms such as < and >. This is not the same as a modern PCRE2 regular-expression engine.
Characters such as ., *, [, ], ^, and $ can have special meaning in regex mode. For an exact string, use /l and /c::
findstr /s /i /l /c:"C:Program FilesTooltool.exe" "C:Scripts*.bat"
Search for multiple terms
For single-word terms, provide several search strings:
findstr /s /i /l /n "net use robocopy schtasks" "C:Scripts*.bat"
For phrases, use separate /c: arguments:
findstr /s /i /l /n /c:"net use" /c:"robocopy C:" "C:Scripts*.bat"
For a larger list, put one search term per line in searches.txt:
Rank #3
net use
robocopy
schtasks
Then run:
findstr /s /i /l /n /g:searches.txt "C:Scripts*.bat" "C:Scripts*.cmd"
The /g: switch reads search strings from a file. Microsoft also documents /f: for reading the list of files to search.
Search with PowerShell
PowerShell separates file selection from text matching. Get-ChildItem -Recurse supplies the files, and Select-String searches their contents.
Get-ChildItem "C:Scripts" -Recurse -File -Include *.bat,*.cmd |
Select-String -SimpleMatch -Pattern "robocopy"
-SimpleMatch makes the pattern literal. Without it, Select-String interprets the pattern as a regular expression.
Recommended Free Tools
Return only one result per matching file
Get-ChildItem "C:Scripts" -Recurse -File -Include *.bat,*.cmd |
Select-String -SimpleMatch -Pattern "robocopy" -List |
Select-Object -ExpandProperty Path
-List stops after the first match in each file, while the final command prints only the paths.
Show surrounding lines
Get-ChildItem "C:Scripts" -Recurse -File -Include *.bat,*.cmd |
Select-String -SimpleMatch -Pattern "robocopy" -Context 3,3
-Context 3,3 displays three lines before and three lines after each match, which is useful for understanding variables, conditions, and arguments around a command.
Use regex, case sensitivity, and encoding options
Regex search:
Get-ChildItem "C:Scripts" -Recurse -File -Include *.bat,*.cmd |
Select-String -Pattern 'sets+PATH'
PowerShell matching is normally case-insensitive. Add -CaseSensitive when capitalization matters:
Get-ChildItem "C:Scripts" -Recurse -File -Include *.bat,*.cmd |
Select-String -SimpleMatch -CaseSensitive -Pattern "Error"
Legacy batch files may use a Windows code page, UTF-8, or UTF-16. If a visible string is missed, specify the encoding after identifying the file’s format:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Select-String -Path "C:Scriptsexample.bat" `
-Pattern "text" `
-SimpleMatch `
-Encoding UTF8
In the documented current PowerShell view, a byte-order mark is used when present and UTF-8 is otherwise assumed; older files may require an explicit encoding. PowerShell 7.4 and later also support the Ansi encoding value.
Search a protected location
Starting with a directory you own is preferable. Searches across C:, C:Windows, another user’s profile, or protected network locations can produce access errors. If you are authorized to inspect the location, an elevated PowerShell window may be required.
Get-ChildItem "C:" -Recurse -File -Include *.bat,*.cmd -ErrorAction SilentlyContinue |
Select-String -SimpleMatch -Pattern "powershell.exe" -ErrorAction SilentlyContinue
Suppressing errors makes output cleaner but can hide files that were not readable. A no-match result from this command does not prove that the string is absent from the entire drive.
Use ripgrep for large or cross-platform searches
ripgrep (rg) is an optional command-line search tool available for Windows, macOS, and Linux. It searches recursively by default and provides precise file globs and exclusions.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →rg -n -i -F --glob "*.bat" --glob "*.cmd" "robocopy C:Source" "C:Scripts"
-nshows line numbers.-iignores case.-Fperforms a fixed-string search instead of regex matching.--globrestricts the files searched.-llists matching filenames only.-g "!vendor/**"excludes a directory.
For example, list only matching batch-script paths:
Best Value
rg -l -i -F --glob "*.bat" --glob "*.cmd" "robocopy" "C:Scripts"
By default, ripgrep skips hidden files, binary files, and files excluded by .gitignore, .ignore, or .rgignore. To broaden the search:
rg -uuu -a -n -i -F "text" "C:Scripts"
-uuu relaxes automatic filtering, and -a treats binary input as text. These options can increase noise and produce unreadable output. For a known encoding, such as UTF-16:
rg -n -F -E utf-16 "robocopy" "C:Scripts"
Performance depends on the storage device, number and size of files, pattern, and filtering. Consult the project repository for supported platforms and releases.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Search from Linux, macOS, WSL, or Git Bash
GNU grep provides the conventional recursive command:
grep -RniF --include='*.bat' --include='*.cmd' -- 'YOUR COMMAND OR STRING' /path/to/folder
The options mean recursive search (-R), line numbers (-n), case-insensitive matching (-i), and fixed-string matching (-F). To list only matching files:
grep -RliF --include='*.bat' --include='*.cmd' -- 'robocopy' /path/to/folder
The -- separates the search pattern from options, which is useful when the pattern begins with a hyphen. See the GNU grep manual for recursive, include, exclude, and binary-file behavior.
Why a search may find nothing
- Wrong root directory: confirm the path and try one known file first.
- Wrong extension: include both
*.batand*.cmd, or temporarily inspect the directory by filename. - Literal text treated as regex: use
/l,-SimpleMatch,-F, or-fas appropriate. - Case mismatch: add
/ior-i; PowerShell is normally case-insensitive unless-CaseSensitiveis used. - Unexpected encoding: retry with the file’s actual UTF-8, UTF-16, ANSI, or legacy code-page setting.
- Line breaks: ordinary searches are line-oriented. A command split with a caret or across multiple lines may not match as one phrase; search for a distinctive fragment on each line or use a multiline-capable workflow.
- Excluded files: ripgrep may skip hidden, ignored, or binary files until filtering is relaxed.
- Unreadable files: access-denied errors mean the scan was incomplete.
What these tools cannot search reliably
findstr, Select-String, rg, and grep are text-search tools, not parsers for Word documents, PDFs, ZIP archives, databases, or compiled executables. Extract the text first when necessary. ripgrep can use options such as -z for supported compressed input or --pre to pass files through a preprocessor such as pdftotext, but those options do not automatically understand every file format.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick reference
| Goal | Command |
|---|---|
| Search batch contents in Command Prompt | findstr /s /i /n /l /c:"text" "C:Folder*.bat" "C:Folder*.cmd" |
| List matching batch filenames | findstr /s /i /m /l /c:"text" "C:Folder*.bat" "C:Folder*.cmd" |
| Search batch contents in PowerShell | Get-ChildItem "C:Folder" -Recurse -File -Include *.bat,*.cmd | Select-String -SimpleMatch -Pattern "text" |
| List matching paths in PowerShell | Get-ChildItem "C:Folder" -Recurse -File -Include *.bat,*.cmd | Select-String -SimpleMatch -Pattern "text" -List | Select-Object -ExpandProperty Path |
| Search with ripgrep | rg -n -i -F --glob "*.bat" --glob "*.cmd" "text" "C:Folder" |
| Search with GNU grep | grep -RniF --include='*.bat' --include='*.cmd' -- 'text' /path/to/folder |
| Find batch files by name | where /r "C:Folder" *.bat and where /r "C:Folder" *.cmd |
Safety reminder
Searching files is generally read-only. Opening an unfamiliar .bat or .cmd file in a text editor is safer than executing it, but do not run a script merely because your search found it. Batch files can delete files, change system settings, download programs, or launch other scripts.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




