Rename filename - switching words

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
okan
Posts: 4
Joined: 06 Oct 2017 02:29

Rename filename - switching words

#1 Post by okan » 06 Oct 2017 03:07

Hello DosTips

I want to create a batch for my problem.
I have many pictures of people with the filename: name_forename.jpg
Now i wantto rename them to: forename.name.jpg but i can't use "ren" on windows for switching words. :cry:

Can someone help me with an example?

Thank you very much...


Regards

Okan Koc

Aacini
Expert
Posts: 1886
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Rename filename - switching words

#2 Post by Aacini » 06 Oct 2017 07:24

Code: Select all

for /F "tokens=1-3 delims=_." %%a in ('dir /B /A-D *_*.jpg') do ren "%%a_%%b.%%c" "%%b.%%a.%%c"

Antonio

okan
Posts: 4
Joined: 06 Oct 2017 02:29

Re: Rename filename - switching words

#3 Post by okan » 11 Oct 2017 01:29

Hi Antonio

Thanks for your fast Response.

But how can I define the path where the pictures are?
In the best situation, i should give a new path where the pictures should be created again with the new name.

Regards

Okan

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Rename filename - switching words

#4 Post by Squashman » 11 Oct 2017 09:14

okan wrote:In the best situation, i should give a new path where the pictures should be created again with the new name.

Did you happen to read the help file for the RENAME command. Read the last line.

Code: Select all

H:\>ren /?
Renames a file or files.

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

Note that you cannot specify a new drive or path for your destination file.


You have now changed the parameters of your question which wastes time for the person who helped who now has to go back and change their code.
Before you post anymore question on the forums please read the thread that we have pinned to the top of the forum
How to get help for a batch script - quickly!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Rename filename - switching words

#5 Post by aGerman » 11 Oct 2017 09:58

Use MOVE instead of REN if you want to move the files to another directory with a new name.

Code: Select all

for /F "tokens=1-3 delims=_." %%a in ('dir /B /A-D *_*.jpg') do move "%%a_%%b.%%c" "c:\wherever\%%b.%%a.%%c"
If you rather want to preserve the original files use COPY the same way.

Steffen

okan
Posts: 4
Joined: 06 Oct 2017 02:29

Re: Rename filename - switching words

#6 Post by okan » 30 Oct 2017 00:45

Hello aGerman

I am writing for the first time a script.
I really don't know where i specify the source (the path where my pictures are..).
Can you help me about this problem?

Thanks in forward..

regards okan

SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Re: Rename filename - switching words

#7 Post by SIMMS7400 » 30 Oct 2017 01:27

Replace source variable with the correct path and retest.

Code: Select all

set "source=C:\source\directory"
pushd "%source%"
for /F "tokens=1-3 delims=_." %%a in ('dir /B /A-D *_*.jpg') do move "%%a_%%b.%%c" "c:\wherever\%%b.%%a.%%c"
popd

okan
Posts: 4
Joined: 06 Oct 2017 02:29

Re: Rename filename - switching words

#8 Post by okan » 30 Oct 2017 01:59

perfect..

Thank you very mutch.. :lol: :lol: :lol:

Post Reply