Using the code below I add text to end of file names which are:
1.mp32.mp3
and should be:
1text.mp32text.mp3
but it changed to:
1.mp3text2.mp3text
Code:
@ECHO ONFOR %%A IN ("C:Usersuser123Desktopmp3*.mp2") DO ( CALL :RenameFiles "%%~A" "%%~NXA")GOTO EOF:RenameFilesSET fname=%~2SET renname=%fname=%REN "%~1" "%renname%text%"GOTO E
Solution:
How do I add "text" to the end of multiple filenames.
Before: 1.mp3 2.mp3
After: 1text.mp3 2text.mp3
There are multiple errors in your batch file, for example:
*.mp2
should be*.mp3
goto E
– the label:E
is missing.- you dont need to
call
anything.
Simple working batch file
rem @echo offsetlocalsetlocal enabledelayedexpansionfor %%a in ("C:Usersuser123Desktopmp3*.mp3") do ( copy "%%a" "%%~dpnatext%%~xa" del "%%a" )endlocal
Notes:
- The batch file will work with any length filename, so for example,
12345.mp3
will be rename to12345text.mp3
cmd
shell solution
You don’t need to use a batch file. You can just use:
cd C:Usersuser123Desktopmp3ren ?.mp3 ?text.mp3
Or:
ren *.mp3 ?text.mp3
Note that the following does not work:
ren *.mp3 *text.mp3
You will get filenames like 1.mp3text.mp3
with that command.
Example:
F:test>dir *.mp3 Volume in drive F is Expansion Volume Serial Number is 3656-BB63 Directory of F:test29/11/2015 12:52 0 1.mp329/11/2015 12:52 0 2.mp3 2 File(s) 0 bytes 0 Dir(s) 1,777,665,769,472 bytes freeF:test>ren ?.mp3 ?text.mp3F:test>dir *.mp3 Volume in drive F is Expansion Volume Serial Number is 3656-BB63 Directory of F:test29/11/2015 12:52 0 1text.mp329/11/2015 12:52 0 2text.mp3 2 File(s) 0 bytes 0 Dir(s) 1,777,665,769,472 bytes free
Further Reading
- An A-Z Index of the Windows CMD command line – An excellent reference for all things Windows cmd line related.
- for – Conditionally perform a command on several files.
- parameters – A command line argument (or parameter) is any value passed into a batch script.