Gentoo Archives: gentoo-user

From: Pandu Poluan <pandu@××××××.info>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Changing names of LOTS of files, adding to them actually.
Date: Thu, 01 Dec 2011 02:35:23
Message-Id: CAA2qdGVjW3jZQFBQqeNJFHHzZbfnAfOo3QZxk=3=D0AB3Mtoig@mail.gmail.com
In Reply to: Re: [gentoo-user] Changing names of LOTS of files, adding to them actually. by Pandu Poluan
1 On Dec 1, 2011 9:22 AM, "Pandu Poluan" <pandu@××××××.info> wrote:
2 >
3 >
4 > On Dec 1, 2011 8:54 AM, "Dale" <rdalek1967@×××××.com> wrote:
5 > >
6 > > Greets,
7 > >
8 > > I ran into a problem. I been downloading a lot of TV shows. I forgot
9 to put a sort of important part in the names. This is what I have with the
10 full path:
11 > >
12 > > /data/Movies/TV_Series/Person of Interest/Season 1, Episode 1 -
13 Pilot.mp4
14 > >
15 > > This is what I need it to be:
16 > >
17 > > /data/Movies/TV_Series/Person of Interest/Person of Interest - Season
18 1, Episode 1 - Pilot.mp4
19 > >
20 > > Basically, I need to add the name of the show to the name of the file.
21 They will all be added to the front of the names. They also almost all
22 contain spaces, which means some fancy footwork with the \.
23 > >
24 > > Is there a way to do this? I have room to copy them to another
25 directory if needed. I would sort of actually prefer it that way since if
26 it messes up, I got the originals at least.
27 > >
28 > > Sorry I'm not real good at gawk, sed and all those things. I suspect
29 those will be used tho. I am familiar with | and grep tho. ;-)
30 > >
31 > > Thoughts?
32 > >
33 >
34 > 'find' and 'mv' should do the job. With some help from 'dirname' and
35 'basename'. E. g.
36 >
37 > find $PATHTOMOVIES -name "*. mp4" -exec mv "{}" "\$(dirname
38 {})/$(basename $(dirname {})) - $(basename {})"
39 >
40 > Not tested, though. So you'd better use 'echo' instead of 'mv' for a dry
41 run.
42 >
43
44 Whoopsies. I certainly must've made some mistakes with the escaping
45 there...
46
47 Oh well, just write a short script containing this:
48
49 mv "$1" "$(dirname $1)/$(basename $(dirname $1)) - $(basename $1)"
50
51 and feed that script (after chmod +x, of course) to the -exec part of
52 find, e.g.
53
54 find ... -exec scriptname.sh {} \;
55
56 Rgds,