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.

user1603548
  • 572
  • 6
  • 21

2 Answers2

1

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

ren keyword_uniqueFilename*.txt MyNewKeyword_uniqueFilename*.txt
Hagen von Eitzen
  • 598
  • 1
  • 6
  • 21
  • but then I will have to modify the command for each file? – user1603548 Aug 29 '14 at 16:44
  • @user1603548 No, if your file names are as listed in the question and should be modified as listed in the question, then this one line command will perform the renaming exactly as desired. – Hagen von Eitzen Aug 31 '14 at 21:05
  • @user1603548 refer : [How does the Windows RENAME command interpret wildcards?](http://superuser.com/questions/475874/how-does-the-windows-rename-command-interpret-wildcards) – Ani Menon Apr 22 '16 at 18:30
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
  • 130
  • 5