On Dec 1, 2011 9:22 AM, "Pandu Poluan" <[email protected]> wrote:
>
>
> On Dec 1, 2011 8:54 AM, "Dale" <[email protected]> wrote:
> >
> > Greets,
> >
> > I ran into a problem.  I been downloading a lot of TV shows.  I forgot
to put a sort of important part in the names.  This is what I have with the
full path:
> >
> > /data/Movies/TV_Series/Person of Interest/Season 1, Episode 1 -
Pilot.mp4
> >
> > This is what I need it to be:
> >
> > /data/Movies/TV_Series/Person of Interest/Person of Interest - Season
1, Episode 1 - Pilot.mp4
> >
> > Basically, I need to add the name of the show to the name of the file.
 They will all be added to the front of the names.  They also almost all
contain spaces, which means some fancy footwork with the \.
> >
> > Is there a way to do this?  I have room to copy them to another
directory if needed.  I would sort of actually prefer it that way since if
it messes up, I got the originals at least.
> >
> > Sorry I'm not real good at gawk, sed and all those things.  I suspect
those will be used tho.  I am familiar with | and grep tho.  ;-)
> >
> > Thoughts?
> >
>
> 'find' and 'mv' should do the job.  With some help from 'dirname' and
'basename'.  E. g.
>
> find $PATHTOMOVIES -name "*. mp4" -exec mv "{}" "\$(dirname
{})/$(basename $(dirname {})) - $(basename {})"
>
> Not tested, though. So you'd better use 'echo' instead of 'mv' for a dry
run.
>

Whoopsies. I certainly must've made some mistakes with the escaping
there...

Oh well,  just write a short script containing this:

mv "$1" "$(dirname $1)/$(basename $(dirname $1)) - $(basename $1)"

and feed that script (after chmod +x,  of course) to the -exec part of
find, e.g.

find ... -exec scriptname.sh {} \;

Rgds,

Reply via email to