ValtZ
ValtZ

Reputation: 1

Powershell rename multiple files in bulk (replace .txt with _,txt)

How to Rename multiple files that I have from 1.txt, 2.txt to something like 1_A.txt 2_A.txt I tried the code below but it didn't work

dir | rename-item -NewName {$_.name -replace ".txt ","_A.txt"}

Can someone give me some guidance how to do this, since I have 100 files to rename

Upvotes: 0

Views: 109

Answers (2)

Io-oI
Io-oI

Reputation: 2565

You can use PowerShell:

 Replace:
             $_.name -replace ".txt ","_A.txt"
      To: 
             ($_.basename+'_A.txt')

 ls *.txt | ? {ren $_.fullname -New ($_.basename+'_A.txt')}

Upvotes: 0

Compo
Compo

Reputation: 38623

…and based upon your tag:

for %I in ("*.txt") do @ren "%I" "%~nI_A%~xI"

Upvotes: 1

Related Questions