How to replace text in multiple files at once using Notepad++

The easiest way to find and replace text inside multiple text files simultaneously in Windows is to use Notepad++, which is free.

Method 1 – Notepad++ (recommended)

  1. Download and install Notepad++ from https://notepad-plus-plus.org/.
  2. Open Notepad++.
  3. Press Ctrl + Shift + F to open Find in Files.
  4. Complete the following fields:
FieldExample
Find whatOld text
Replace withNew text
Filters*.txt
DirectoryD:\rubbish\data
In all sub-foldersTick if required
Match caseTick if capitalisation matters
Search ModeNormal
  1. Click Find All if you want to preview the matches before making changes.
  2. Click Replace in Files.
  3. Confirm the operation.

Notepad++ will automatically open, modify and save the relevant files.

Different file types

You can restrict the operation to particular types of files:

FilterFiles affected
*.txtText files
*.csvCSV data files
*.pyPython scripts
*.cppC++ source code
*.grcGNU Radio flowgraphs
*.txt *.csvBoth text and CSV files
*.*All file types

Method 2 – Windows PowerShell

You can also do this without installing additional software.

For example, to replace Old text with New text inside every text file in a directory:

Get-ChildItem “D:\rubbish\data” -Filter *.txt | ForEach-Object {

    $content = Get-Content $_.FullName -Raw

    $content = $content.Replace(“Old text”, “New text”)

    Set-Content $_.FullName -Value $content -NoNewline

}

To include all subdirectories, add -Recurse after -Filter *.txt.

Be aware that PowerShell may change the character encoding of your files, depending on the version used.

I would recommend Notepad++, particularly for modifying large numbers of radio astronomy data files or software source files.

Important: Make a backup of the directory before performing a bulk replacement, as changes across multiple files may not be easily undone.

By Admin

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.