• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

rename multiple files using command prompt

general command to rename extensions of multiple files using command prompt in windows is
ren *.html *.txt

but if i want to rename a file from something like below to
ABC_4739874_2349827.txt
to
ABC_4739874_2349827_RENAMED.txt

how can i do that.

Thanks
0
shragi
Asked:
shragi
  • 4
  • 3
  • 3
  • +1
1 Solution
 
NVITCommented:
for %A in (*.txt *.html) do ren %~nA_RENAMED%~xA
0
 
Joseph DalyCommented:
Using powershell.

$dir = "C:\filepath"
gci $dir | foreach {
$name = $_.name
$newname = $name+"_renamed"
rename-item $dir\$name $newname
}

Open in new window

0
 
Jonathan BriteSystem AdminCommented:
You can use wild cards in command line with rename.  I am pretty sure your example would be (without quotes) "rename ABC_*.txt ABC_*_RENAMED.txt"  

I also think Josephs PS script would be much cleaner, especially if going through multiple directories)
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
shragiAuthor Commented:
@NewVillageIT
I got error saying "the syntax of the command is incorrect"
for %A in (*.txt) do ren %~nA_RENAMED%~xA
0
 
Jonathan BriteSystem AdminCommented:
have you tried a normal rename command like I listed above yet? (be sure to test it before trying it globally)
0
 
NVITCommented:
Correction to my CMD version:
for %A in (*.txt *.html) do ren "%A" "%~nA_RENAMED%~xA"

Open in new window

0
 
NVITCommented:
To rename in disparate folders:
for %A in (c:\dir1\*.txt c:\dir2\*.txt) do ren "%A" "%~nA_RENAMED%~xA"

Open in new window


To rename in current and sub-folders:
for /r %A in (*.txt *.html) do ren "%A" "%~nA_RENAMED%~xA"

Open in new window

0
 
shragiAuthor Commented:
@Jonathan Brite

your command is not working - it is renaming wrongly
ABC_4739874_2349827.txt is renamed to ABC_4739874_RENAMED.txt
but i want it to be renamed to
ABC_4739874_2349827_RENAMED.txt
0
 
Jonathan BriteSystem AdminCommented:
Thanks NewVillageIT.  That helped me as well.
0
 
shragiAuthor Commented:
thanks newvillageIT :)
0
 
NVITCommented:
I'm glad it worked for you, shragi, and Jonathan. Have a nice day...8-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now