How to replace a word in all .txt files of a folder

including sub folders, on the Windows command line - Noob vs. Pro

AI Noob Answer:

"you can use the "forfiles" and "findstr" commands:

for /f %i in ('dir /b /s /a-d "C:\path\to\folder\*.txt"') do @(type "%i" | findstr /v "old_word" > "%i.tmp" &move "%i.tmp" "%i") ... I see the an old_word, but not a new_word. So I won't try that.

This command will search recursively ... blabla ... ... no, it must read: this command will do bullshit and waste your time.

Alternatively use a "powershell" command:

Get-ChildItem -Path "C:\path\to\folder" -Filter *.txt -Recurse -Force | ForEach-Object { (Get-Content $_.FullName) -replace "old_word", "new_word" | Set-Content $_.FullName } ... incredible, it worked.

Great solution! ... if you have an alien neighbour who can translate it for humans.

But if he can't, you're rather lost, and need the

Pro Answer:

Forget the above junk, download the free open source SFK for any system and type in one line:

sfk replace -dir mydir
  -file .txt
  -pattern "/word1/word2/"

Done. Example output shows a mix of hex dump (needed with binary files) and replaced text:

[simulating:]
mydir\foo.txt : hit at offset 0x8

>68657265 2069...< here is word2 an
>64207468 6520...< d the like....
[001/1/0] mydir\foo.txt
51 files checked, 1 would be changed.
[add -yes to write changes.]

Default is to preview changes, without actually writing them. Add option -yes to really change files.

Read the full syntax here.

Incredible command sighted!
   How to list different files between two folders

Secret command discovered!
   How to list all files having a word in their filename