Bulk Replace
How-to

How to Find and Replace Text in Multiple Files at Once on Windows

Find and replace text in multiple files at once on Windows. Compare PowerShell, editor find-in-files and a batch tool, with preview and undo steps.

Updated 6 minute read The Bulk Replace team

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:

  1. Get-ChildItem -Recurse -File -Filter *.html lists every .html file in the folder and all subfolders.
  2. Get-Content -Raw reads each file as one string, so multi-line text and line breaks stay intact.
  3. -replace performs the replacement. It uses regular expressions and ignores case by default.
  4. Set-Content -NoNewline writes 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

  1. Open the folder with File → Open Folder.
  2. Press Ctrl+Shift+H to open Search with the replace box showing.
  3. Type the search text and the replacement. Use the files to include box (for example *.html, *.css) to limit the scope.
  4. Review the results list. You can dismiss individual matches before replacing.
  5. Click Replace All (Ctrl+Alt+Enter).

Notepad++

  1. Press Ctrl+Shift+F to open Find in Files.
  2. Fill in Find what, Replace with, Filters (such as *.html *.css) and Directory.
  3. Tick In all sub-folders if you need them.
  4. 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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?

NeedPowerShellEditor replace in filesBatch tool
Nothing to installYesIf you already have oneNo
See every match before savingOnly with extra commandsYes, in the results listYes, as a before/after diff
Undo the whole runNoNot for closed filesYes, from automatic backups
Many different replacements at onceChain -replace callsOne at a timeStacked rules or CSV import
Keeps file encodingsOnly if you set -EncodingUsuallyYes, detected per file
Rename files as wellSeparate commandNoYes, 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/2025 that should become 2025-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\b so 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 art also changes start and party. Use whole-word matching.
  • Wrong case. PowerShell -replace and 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

  1. Search for the old text again. The count should be zero, or exactly the matches you chose to keep.
  2. Search for the new text and compare the count with what you expected.
  3. Open a few changed files, or run the site or program, and check that everything still works.
  4. 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.

Get three guides like this every month, plus software update notices.Subscribe →