shragi
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_RENAME D.txt
how can i do that.
Thanks
ren *.html *.txt
but if i want to rename a file from something like below to
ABC_4739874_2349827.txt
to
ABC_4739874_2349827_RENAME
how can i do that.
Thanks
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
}
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)
I also think Josephs PS script would be much cleaner, especially if going through multiple directories)
ASKER
@NewVillageIT
I got error saying "the syntax of the command is incorrect"
for %A in (*.txt) do ren %~nA_RENAMED%~xA
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"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_RENAME D.txt
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_RENAME
Thanks NewVillageIT. That helped me as well.
ASKER
thanks newvillageIT :)
I'm glad it worked for you, shragi, and Jonathan. Have a nice day...8-)