How do you rename a bunch of files using wildcards?
I'm trying to do something that seems straightforward and intuitive, but for some reason it's not working. I have a directory of files that are named (001.bmp.jpg, 002.bmp.jpg, etc.) and I'm trying to rename them to get rid of the .bmp part using the following:
rename *.bmp.jpg *.jpg
The above command has no effect.
However, I can rename files like this
rename *.bmp *.txt
and that works.
Am I missing something?
Renaming files with wildcards
Moderator: DosItHelp
Re: Renaming files with wildcards
Greetings bobt_1234!
That period or 'full stop' after 001 and 002 is reeking havoc with your renaming process.
I did limited testing on the script below based on your examples also no error checking for the
existence of a file named $bobt_1234.bat
Examine $bobt_1234$.bat to ensure you are getting the desired
results.
Best wishes!
That period or 'full stop' after 001 and 002 is reeking havoc with your renaming process.
I did limited testing on the script below based on your examples also no error checking for the
existence of a file named $bobt_1234.bat
Code: Select all
@echo off
setlocal
echo.@echo off>$bobt_1234$.bat
for /f "delims=" %%a in ('dir *.jpg /b') do call :go "%%a"
goto :EOF
:go
set "var=%~n1"
set var=%var:~0,3%
echo ren %~1 %var%.jpg>>$bobt_1234$.bat
endlocal
Examine $bobt_1234$.bat to ensure you are getting the desired
results.
Best wishes!
Re: Renaming files with wildcards
Wow, thanks. I didn't know you could do all that in a bat file.
I have a couple questions.
1. Why is the parameter referred to as %~n1 at the beginning but as %~1 in the rename.
2. I'm assuming the line "var=%var:~0,3% a substring command?
I have a couple questions.
1. Why is the parameter referred to as %~n1 at the beginning but as %~1 in the rename.
2. I'm assuming the line "var=%var:~0,3% a substring command?
Re: Renaming files with wildcards
Greetings bobt_1234
1. A mistake I made in the original file which I copied/pasted in my reply. %~1 should work in both places. Good eye!
2. Grabs the 001,002 from your file name examples.
Did the script work properly for you?
Best wishes!
1. Why is the parameter referred to as %~n1 at the beginning but as %~1 in the rename.
2. I'm assuming the line "var=%var:~0,3% a substring command?
1. A mistake I made in the original file which I copied/pasted in my reply. %~1 should work in both places. Good eye!
2. Grabs the 001,002 from your file name examples.
Did the script work properly for you?
Best wishes!