0

I'm on windows 7 and have a folder of txt and all txt are named

keyword_uniqueFileName.txt

keyword_uniqueFileName2.txt

keyword_uniqueFileName3.txt

and would like to bulk change them to

MyNewKeyword_uniqueFileName.txt

MyNewKeyword_uniqueFileName2.txt

MyNewKeyword_uniqueFileName3.txt

Either using some program or the command line.

Worst case I'll have to go to my Kubuntu machine and use some command there.

2 Answers2

1

Within a command line window ("DOS box"), try

ren keyword_uniqueFilename*.txt MyNewKeyword_uniqueFilename*.txt
0

Using powershell :

powershell -C "gci | % {rni $_.Name ($_.Name -replace 'keyword', 'MyNewKeyword')}"

Explanation

powershell -C "..." launches a PowerShell session to run the quoted command. It returns to the outer shell when the command completes. -C is short for -Command.

gci returns all the files in the current directory. It is an alias for [Get-ChildItem][gci].

| % {...} makes a pipeline to process each file. % is an alias for [Foreach-Object][%].

$_.Name is the name of the current file in the pipeline.

($_.Name -replace 'KW1', 'KW2') uses the -replace operator to create the new file name. Each occurrence of the first substring is replaced with the second substring.

rni changes the name of each file. The first parameter (called -Path) identifies the file. The second parameter (called -NewName) specifies the new name. rni is an alias for [Rename-Item][rni].

Refer

Ani Menon
  • 150