- Batch file rename?
- Posted by Justin on December 20th, 2005
I have a client with a BUNCH of files. Hundreds. The first name with
an underscore then the last name dot jpg. Is there a way to get it
from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
- Posted by billious on December 20th, 2005
"Justin" <Acurajustin1978@hotmail.com> wrote in message
news:1135101772.167654.166150@g43g2000cwa.googlegr oups.com...
>I have a client with a BUNCH of files. Hundreds. The first name with
> an underscore then the last name dot jpg. Is there a way to get it
> from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
>
Of course! Anything worth doing can be done in batch.
(see alt.msdos.batch.nt for nt/2k/xp methods; alt.msdos.batch for DOS/9x
methods and microsoft.public.win2000.cmdprompt)
As for your problem :-
for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2delims=_." %%j in
("%%i") do ECHO ren %%i %%k_%%j.jpg
(all as one batch line. Reduce each "%%" to "%" if executed directly from
the prompt)
(the "ECHO" command is included for you to verify that the operation is
kosher. remove the "ECHO" to execute the rename)
HTH
....Bill
- Posted by Justin on December 20th, 2005
billious wrote:
> "Justin" <Acurajustin1978@hotmail.com> wrote in message
> news:1135101772.167654.166150@g43g2000cwa.googlegr oups.com...
> >I have a client with a BUNCH of files. Hundreds. The first name with
> > an underscore then the last name dot jpg. Is there a way to get it
> > from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
> >
>
> Of course! Anything worth doing can be done in batch.
>
> (see alt.msdos.batch.nt for nt/2k/xp methods; alt.msdos.batch for DOS/9x
> methods and microsoft.public.win2000.cmdprompt)
>
> As for your problem :-
>
> for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2delims=_." %%j in
> ("%%i") do ECHO ren %%i %%k_%%j.jpg
>
> (all as one batch line. Reduce each "%%" to "%" if executed directly from
> the prompt)
> (the "ECHO" command is included for you to verify that the operation is
> kosher. remove the "ECHO" to execute the rename)
>
> HTH
>
> ...Bill
DOH!
It turns out that won't work. The client has somethign else which he
neglected to tell me.
example richard_parks_123.jpg
has to end up parks_richard_123.jpg the 123 is a variable number of
digits. Grrr... I'm adding another two hours to this guy's bill.
- Posted by Armin on December 20th, 2005
Justin wrote:
> billious wrote:
> > "Justin" <Acurajustin1978@hotmail.com> wrote in message
> > news:1135101772.167654.166150@g43g2000cwa.googlegr oups.com...
> > >I have a client with a BUNCH of files. Hundreds. The first name with
> > > an underscore then the last name dot jpg. Is there a way to get it
> > > from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
> > >
> >
> > Of course! Anything worth doing can be done in batch.
> >
> > (see alt.msdos.batch.nt for nt/2k/xp methods; alt.msdos.batch for DOS/9x
> > methods and microsoft.public.win2000.cmdprompt)
> >
> > As for your problem :-
> >
> > for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2delims=_." %%j in
> > ("%%i") do ECHO ren %%i %%k_%%j.jpg
> >
> > (all as one batch line. Reduce each "%%" to "%" if executed directly from
> > the prompt)
> > (the "ECHO" command is included for you to verify that the operation is
> > kosher. remove the "ECHO" to execute the rename)
> >
> > HTH
> >
> > ...Bill
>
>
> DOH!
>
> It turns out that won't work. The client has somethign else which he
> neglected to tell me.
> example richard_parks_123.jpg
> has to end up parks_richard_123.jpg the 123 is a variable number of
> digits. Grrr... I'm adding another two hours to this guy's bill.
Two hours billing for a 5 minute change to a batch file someone else
wrote for you for free?
Remind me not to hire you!
- Posted by Andy C.(never #) on December 20th, 2005
Justin wrote:
> SNIP<
> It turns out that won't work. The client has somethign else which he
> neglected to tell me.
> example richard_parks_123.jpg
> has to end up parks_richard_123.jpg the 123 is a variable number of
> digits. Grrr... I'm adding another two hours to this guy's bill.
You can program in Perl on a windows PC. In Linux, I would do
#!/usr/bin/perl -w
opendir(DIR,'./your_directory/') or die;
@bar = readdir(DIR);
foreach $file (@bar) {
if (-d $file) {
#skip the dots
} else {
@names=split('_',$file);
# now you have the file name in $names[0]='parks'
$names[1]='richard'
$names[2]='123.rpg'
So, if you want to reverse the name,
move or copy
system("mv $file $names[1]_$names[0]_$names[2]");
}
}
Oh, you definitely want to have the correct path information in that
system call to mv.
HTH,
Andy C.(never #)
- Posted by Justin on December 20th, 2005
Armin wrote:
> Justin wrote:
> > billious wrote:
> > > "Justin" <Acurajustin1978@hotmail.com> wrote in message
> > > news:1135101772.167654.166150@g43g2000cwa.googlegr oups.com...
> > > >I have a client with a BUNCH of files. Hundreds. The first name with
> > > > an underscore then the last name dot jpg. Is there a way to get it
> > > > from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
> > > >
> > >
> > > Of course! Anything worth doing can be done in batch.
> > >
> > > (see alt.msdos.batch.nt for nt/2k/xp methods; alt.msdos.batch for DOS/9x
> > > methods and microsoft.public.win2000.cmdprompt)
> > >
> > > As for your problem :-
> > >
> > > for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2delims=_." %%j in
> > > ("%%i") do ECHO ren %%i %%k_%%j.jpg
> > >
> > > (all as one batch line. Reduce each "%%" to "%" if executed directly from
> > > the prompt)
> > > (the "ECHO" command is included for you to verify that the operation is
> > > kosher. remove the "ECHO" to execute the rename)
> > >
> > > HTH
> > >
> > > ...Bill
> >
> >
> > DOH!
> >
> > It turns out that won't work. The client has somethign else which he
> > neglected to tell me.
> > example richard_parks_123.jpg
> > has to end up parks_richard_123.jpg the 123 is a variable number of
> > digits. Grrr... I'm adding another two hours to this guy's bill.
>
> Two hours billing for a 5 minute change to a batch file someone else
> wrote for you for free?
>
> Remind me not to hire you!
Figure of speech. Its routine that clients don't give me all the
information, then when I try somethign it doesn't work so its my fault.
If only I were a Betaziod...
- Posted by billious on December 20th, 2005
"Justin" <Acurajustin1978@hotmail.com> wrote in message
news:1135104443.481507.3380@g47g2000cwa.googlegrou ps.com...
>
> billious wrote:
>> "Justin" <Acurajustin1978@hotmail.com> wrote in message
>> news:1135101772.167654.166150@g43g2000cwa.googlegr oups.com...
>> >I have a client with a BUNCH of files. Hundreds. The first name with
>> > an underscore then the last name dot jpg. Is there a way to get it
>> > from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
>> >
>>
>> Of course! Anything worth doing can be done in batch.
>>
>> (see alt.msdos.batch.nt for nt/2k/xp methods; alt.msdos.batch for DOS/9x
>> methods and microsoft.public.win2000.cmdprompt)
>>
>> As for your problem :-
>>
>> for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2delims=_." %%j
>> in
>> ("%%i") do ECHO ren %%i %%k_%%j.jpg
>>
>> (all as one batch line. Reduce each "%%" to "%" if executed directly from
>> the prompt)
>> (the "ECHO" command is included for you to verify that the operation is
>> kosher. remove the "ECHO" to execute the rename)
>>
>> HTH
>>
>> ...Bill
>
>
> DOH!
>
> It turns out that won't work. The client has somethign else which he
> neglected to tell me.
> example richard_parks_123.jpg
> has to end up parks_richard_123.jpg the 123 is a variable number of
> digits. Grrr... I'm adding another two hours to this guy's bill.
>
for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2,3delims=_." %%j
in ("%%i") do if /i "%%l"==".jpg" (echo ren %%i %%k_%%j.jpg) else (echo ren
%%i %%k_%%j_%%l.jpg)
(still one line...)
I'd send you my virtual bill too...been out-of-work more than 4 years now
.... 
....Bill - or not 
- Posted by Lem on December 20th, 2005
Justin wrote:
> I have a client with a BUNCH of files. Hundreds. The first name with
> an underscore then the last name dot jpg. Is there a way to get it
> from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
Take a look at IrfanView (www.irfanview.com). IIRC, it has a bulit-in
batch renaming facility that may do what you want. Even if it doesn't,
it's a great, free, graphics file viewer.
- Posted by Justin on December 21st, 2005
billious wrote:
> "Justin" <Acurajustin1978@hotmail.com> wrote in message
> news:1135104443.481507.3380@g47g2000cwa.googlegrou ps.com...
> >
> > billious wrote:
> >> "Justin" <Acurajustin1978@hotmail.com> wrote in message
> >> news:1135101772.167654.166150@g43g2000cwa.googlegr oups.com...
> >> >I have a client with a BUNCH of files. Hundreds. The first name with
> >> > an underscore then the last name dot jpg. Is there a way to get it
> >> > from henry_smith.jpg to smith_henry.jpg? Any sort of batch program?
> >> >
> >>
> >> Of course! Anything worth doing can be done in batch.
> >>
> >> (see alt.msdos.batch.nt for nt/2k/xp methods; alt.msdos.batch for DOS/9x
> >> methods and microsoft.public.win2000.cmdprompt)
> >>
> >> As for your problem :-
> >>
> >> for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2delims=_." %%j
> >> in
> >> ("%%i") do ECHO ren %%i %%k_%%j.jpg
> >>
> >> (all as one batch line. Reduce each "%%" to "%" if executed directly from
> >> the prompt)
> >> (the "ECHO" command is included for you to verify that the operation is
> >> kosher. remove the "ECHO" to execute the rename)
> >>
> >> HTH
> >>
> >> ...Bill
> >
> >
> > DOH!
> >
> > It turns out that won't work. The client has somethign else which he
> > neglected to tell me.
> > example richard_parks_123.jpg
> > has to end up parks_richard_123.jpg the 123 is a variable number of
> > digits. Grrr... I'm adding another two hours to this guy's bill.
> >
>
> for /f %%i in ('dir /a:-d/b *_*.jpg') do for /f "tokens=1,2,3delims=_." %%j
> in ("%%i") do if /i "%%l"==".jpg" (echo ren %%i %%k_%%j.jpg) else (echo ren
> %%i %%k_%%j_%%l.jpg)
>
> (still one line...)
>
> I'd send you my virtual bill too...been out-of-work more than 4 years now
> ... 
>
> ...Bill - or not 
I'll send virtual money... Just kidding.
That seems to have worked, I tried it on my system and it worked fine.
Now I'm sending it to the technically inept client.