Link to home
Start Free TrialLog in
Avatar of shragi
shragiFlag for India

asked on

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
Avatar of NVIT
NVIT
Flag of United States of America image

for %A in (*.txt *.html) do ren %~nA_RENAMED%~xA
Using powershell.

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

Open in new window

Avatar of Jonathan Brite
Jonathan Brite

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)
Avatar of shragi

ASKER

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shragi

ASKER

@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
Thanks NewVillageIT.  That helped me as well.
Avatar of shragi

ASKER

thanks newvillageIT :)
I'm glad it worked for you, shragi, and Jonathan. Have a nice day...8-)