I'm writing a BAT file for renaming some files.
My files are *.jpg
where * is the file name and I want them to be *-thumb.jpg
.
When trying to do RENAME *.jpg *-thumb.jpg
my files appear as *.jpg-thumb.jpg
.
Actually the RENAME command alone can solve the problem, as long as there is only one .
in the name. Simply use many ?
instead of a single *
.
REN *.jpg ????????????????????-thumb.*
Just make sure the number of ?
is at least as long as the longest file name that will be renamed.
You can ensure that names with multiple .
are not accidentally named by using many ?
in the source mask as well. The following will rename "abc.jpg" to "abc-thumb.jpg", but will leave "abc.xyz.jpg" alone.
REN ????????????????????.jpg ????????????????????-thumb.*
You can rename a file with two dots like "abc.xyz.jpg" using the following.
REN ????????????.????????????.jpg ????????????.????????????-thumb.*
The pattern can be extended for any number of dots in the name.
See How does the Windows RENAME command interpret wildcards? for more info.
Something like:
for %%f in (*.jpg) do rename "%%f" "%%~nf-thumb.jpg"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With