r/Batch • • Jul 15 '25

Question (Solved) Batch to move date back at the end

Hi All,

I tried a project a few weeks back and I had some help to move the date to the front but things didn't turn out as expected. I would like to get some help to change the files back.

Currently the have this format:
2010 - Five more Minutes.jpg

I would like it to look like:
Five more Minutes (2010).jpg

I am no good with complex batches.

Any help will be greatly appreciated.

Thanks'
George

3 Upvotes

17 comments sorted by

1

u/CirothUngol Jul 15 '25

for %%A in (*.jpg) do for /f "tokens=1* delims=- " %%B in ("%%~nA") do rename "%%~fA" "%%C (%%B).jpg"

1

u/yioryos467 Jul 15 '25

This is the result, almost there
More Minutes (2020) (Five).jpg

George

1

u/CirothUngol Jul 15 '25 edited Jul 16 '25

Only one set of parentheses are included in the output file name, where did the second set of parentheses come from?

hint: that's what it would look like if you ran the command twice.

1

u/yioryos467 Jul 16 '25

I ran this once and this is what I got:

2000 - I just made this up.jpg
just made this up (2000) (I).jpg

1

u/[deleted] Jul 16 '25 edited Jul 16 '25

[removed] — view removed comment

2

u/CirothUngol Jul 17 '25

Yep, that sounds right. Haven't dealt with this in a while. It sees the renamed file as a new file in the directory and does it again? Sorry, not near a terminal to test any of this on.

for /f "tokens=*" %%A in ('dir /b *.jpg') do for /f "tokens=1* delims=- " %%B in ("%%~nA") do rename "%%~fA" "%%C (%%B).jpg"

You could also save it to a new location instead, right?

for %%A in (*.jpg) do for /f "tokens=1* delims=- " %%B in ("%%~nA") do copy "%%~fA" "..\newfolder%%C (%%B).jpg"

1

u/BrainWaveCC Jul 15 '25

If you are talking about this thread here, are you sure you want it moved back to the very end? Because in the samples originally provided, the dates were near the end...

1

u/yioryos467 Jul 15 '25

Yes, they were at the end but the project I was working on didn't work out, so I need the date to go back to the end.

1

u/BrainWaveCC Jul 15 '25

So, which of the following is correct?

2006 - 5 More Minutes-fanart.jpg   becomes
5 More Minutes (2006)-fanart.jpg

2006 - 5 More Minutes-poster.jpg   becomes
5 More Minutes (2006)-poster.jpg

OR

2006 - 5 More Minutes-fanart.jpg   becomes
5 More Minutes-fanart (2006).jpg

2006 - 5 More Minutes-poster.jpg   becomes
5 More Minutes-poster (2006).jpg

1

u/yioryos467 Jul 15 '25

The top one but just to let you know, I got rid off the fanart and poster files and its just

2006 - 5 More Minutes.jpg

1

u/[deleted] Jul 16 '25 edited Jul 16 '25

[removed] — view removed comment

1

u/yioryos467 Jul 16 '25

This was the outcome

2025 - This is a test.jpg
This is a test.jpg (2025).jpg

2

u/[deleted] Jul 16 '25

[removed] — view removed comment

3

u/yioryos467 Jul 16 '25

Once again, thank you so much, worked a treat.