I am assuming you know the length of the part before the _
and after the underscore, as well as the extension. If you don't it might be more complex than a simple substring.
cd C:\path\to\the\files
for /f %%a IN ('dir /b *.jpg') do (
set p=%a:~0,3%
set q=%a:~4,4%
set b=%p_%q.jpg
ren %a %b
)
I just came up with this script, and I did not test it. Check out this and that for more info.
IF you want to assume you don't know the positions of the _
and the lengths and the extension, I think you could do something with for loops to check the index of the _
, then the last index of the .
, wrap it in a goto
thing and make it work. If you're willing to go through that trouble, I'd suggest you use WindowsPowerShell (or Cygwin) at least (for your own sake) or install a more advanced scripting language (think Python/Perl) you'll get more support either way.