To find and replace text in multiple files on Windows, you have three practical options: a PowerShell command that rewrites every matching file, the "replace in files" feature of a code editor such as VS Code or Notepad++, or a dedicated batch tool that shows you every match first and can undo the whole run. All three work. The right one depends on how many files you are changing, whether you need to check the matches, and how bad it would be to get it wrong.
This guide walks through each method with exact steps, then covers the checks that stop a bulk replace from turning into a bulk mistake.
Before you start: three quick checks
A replace across hundreds of files is fast, which is exactly why a small error spreads so far. Spend two minutes on these first:
- Make a copy or commit. If the folder is under Git, commit everything first. If not, copy the folder somewhere safe. Most methods below have no undo.
- Know which files you mean. Decide on the extensions (for example
.html,.css,.php) and whether subfolders are included. Never run a replace over images, archives or Office documents. - Search before you replace. Run the search on its own and look at the match count. If you expected 40 matches and see 4,000, your search term is too broad.
Method 1: PowerShell (built into Windows)
PowerShell ships with Windows, so there is nothing to install. Open it from the Start menu, change to your folder with cd, and run:
Get-ChildItem -Recurse -File -Filter *.html | ForEach-Object { $t = Get-Content $_.FullName -Raw; $n = $t -replace 'old text','new text'; if ($n -ne $t) { Set-Content $_.FullName $n -NoNewline } }
What each part does:
Get-ChildItem -Recurse -File -Filter *.htmllists every .html file in the folder and all subfolders.Get-Content -Rawreads each file as one string, so multi-line text and line breaks stay intact.-replaceperforms the replacement. It uses regular expressions and ignores case by default.Set-Content -NoNewlinewrites the result back without adding an extra line break, and only for files that actually changed.
Two things catch people out. First, -replace treats the search as a regex, so characters like . ( and ? have special meanings. For a literal search, use $t.Replace('old text','new text') instead, which is also case-sensitive. Second, encoding: Windows PowerShell 5.1 writes files in the system ANSI code page unless you add -Encoding, which can break accented characters in UTF-8 files. The full details are in our guide to replacing text in multiple files with PowerShell.
Method 2: a code editor's replace in files
If you already use a code editor, it probably has a project-wide replace.
VS Code
- Open the folder with File → Open Folder.
- Press Ctrl+Shift+H to open Search with the replace box showing.
- Type the search text and the replacement. Use the files to include box (for example
*.html, *.css) to limit the scope. - Review the results list. You can dismiss individual matches before replacing.
- Click Replace All (Ctrl+Alt+Enter).
Notepad++
- Press Ctrl+Shift+F to open Find in Files.
- Fill in Find what, Replace with, Filters (such as
*.html *.css) and Directory. - Tick In all sub-folders if you need them.
- Click Find All first to see the matches, then Replace in Files and confirm.
Editors are a good fit when the files are already part of a project you work in. Be aware that a replace in files writes changes to disk for files that are not open, so editor undo cannot bring them back. Our step-by-step guides cover VS Code replace in all files and Notepad++ Replace in Files in more depth.
Method 3: a batch find and replace tool
When the job is large, needs several replacements, or must be reversible, a dedicated tool is the safer route. Bulk Replace is built for exactly this on Windows 7, 8, 10 and 11. The workflow is four steps:
- Choose a folder. Tick include sub-folders and set filters for extensions, file size, modified date and hidden files. Binary files are detected and skipped automatically.
- Add rules. Each rule can be plain text, wildcards or full regex, with case-sensitive and whole-word options. Stack as many rules as you need, or import a list from CSV.
- Preview. A before/after diff shows every match in every file with a total count. Untick any file or individual match you want to leave alone.
- Replace. Every file is backed up before it changes, and one click undoes the whole run if the result is not right. A timestamped report lists the files changed and match counts, and can be exported as CSV.
Bulk Replace also keeps each file in its original encoding (UTF-8, ANSI or UTF-16) unless you choose to convert them all to one.
Which method should you use?
| Need | PowerShell | Editor replace in files | Batch tool |
|---|---|---|---|
| Nothing to install | Yes | If you already have one | No |
| See every match before saving | Only with extra commands | Yes, in the results list | Yes, as a before/after diff |
| Undo the whole run | No | Not for closed files | Yes, from automatic backups |
| Many different replacements at once | Chain -replace calls | One at a time | Stacked rules or CSV import |
| Keeps file encodings | Only if you set -Encoding | Usually | Yes, detected per file |
| Rename files as well | Separate command | No | Yes, in the same run |
For a quick, one-off change in a project you already have open, the editor is fine. For automated jobs on a server, PowerShell is ideal. For anything large, repeated or risky, a tool with preview and undo saves you from the worst outcomes.
Plain text, wildcards or regex?
Most replacements are plain text: one exact phrase becomes another. Switch to regular expressions when the text varies but follows a pattern, for example:
- Dates such as
31/12/2025that should become2025-12-31: find(\d{2})/(\d{2})/(\d{4}), replace with$3-$2-$1. - Any version number after a label: find
version="\d+\.\d+". - A word only when it stands alone: find
\bcat\bso category is left untouched.
Regex is powerful, so test it on a few files or check it in a preview before the full run.
Common mistakes and how to avoid them
- Partial-word matches. Replacing
artalso changes start and party. Use whole-word matching. - Wrong case. PowerShell
-replaceand many editors ignore case by default. Turn on match case when capitalization matters. - Touching the wrong files. Without a filter, a replace may hit minified files, vendor libraries or logs. Filter by extension and check the file list.
- Broken characters. If accented letters turn into odd symbols after the run, the file was written in a different encoding than it was read.
- Office files. Word .docx, Excel .xlsx and PDF files are not plain text. Text tools skip or damage them. Use the program that created them instead.
After the replace: verify
- Search for the old text again. The count should be zero, or exactly the matches you chose to keep.
- Search for the new text and compare the count with what you expected.
- Open a few changed files, or run the site or program, and check that everything still works.
- Keep the backup or commit until you are sure.
If something did go wrong, see how to undo a find and replace in multiple files for recovery options. With a preview before the run and a backup behind it, changing text across thousands of files becomes a routine job rather than a gamble.
Frequently asked questions
Can Windows find and replace text in multiple files without extra software?
Not from File Explorer. You can do it with a PowerShell command that reads each file, runs -replace and writes it back, but there is no preview or undo, so make a backup first.
Is it safe to find and replace across hundreds of files?
It is safe if you can see every match before saving and can roll the change back. Preview the matches, keep a backup of the files you change, and test on a copy of the folder the first time.
Does find and replace work on Word or PDF files?
Not with plain-text tools. Word .docx and PDF files are compressed or binary formats, so text find and replace tools skip them. Use Word itself or a PDF editor for those.
