You are not logged in.

#1 2013-04-23 19:59:19

ssl6
Member
From: Ottawa, ON, CA
Registered: 2007-08-30
Posts: 594

bash script help?

I really need to get a good book to read and learn some bash scripting so I can do this myself. but this is only the 3rd or 4th time i've come here asking

I was hoping someone might be able to assist me again

I'm trying to organize my movie folder again. I've let it go too long

basically, i'm looking for a bash script to go through my folder of movies. each movie has it's own folder with an avi, jpg and nfo. I need the files in the folders to be the same name as the parent folder

so lets say i have this

movie title folder (2012)
-movie_file_2012.avi
-an_nfo_file.nfo
-a_jpg.jpg

I want to turn into this

movie title folder (2012)
-movie title folder (2012).avi
-movie title folder (2012).nfo
-movie title folder (2012).jpg

anyone?


this is a signature

Offline

#2 2013-04-23 20:13:58

cookies
Member
Registered: 2013-01-17
Posts: 253

Re: bash script help?

Maybe this will point you in the right direction http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-12.html

Offline

#3 2013-04-23 20:35:52

lspci
Member
From: Virginia, USA
Registered: 2012-06-09
Posts: 242

Re: bash script help?

ssl6 wrote:

I really need to get a good book to read and learn some bash scripting so I can do this myself. but this is only the 3rd or 4th time i've come here asking

I was hoping someone might be able to assist me again

I'm trying to organize my movie folder again. I've let it go too long

basically, i'm looking for a bash script to go through my folder of movies. each movie has it's own folder with an avi, jpg and nfo. I need the files in the folders to be the same name as the parent folder

so lets say i have this

movie title folder (2012)
-movie_file_2012.avi
-an_nfo_file.nfo
-a_jpg.jpg

I want to turn into this

movie title folder (2012)
-movie title folder (2012).avi
-movie title folder (2012).nfo
-movie title folder (2012).jpg

anyone?

I won't do the work for you, but if you're willing to look things up and try to write a working script that does what you've described--I'll be happy to help flush out problem areas.

Okay, so what you want is to turn

Movies/:

    A-Movie-I-love.avi 
    A-Movie-I-love.nfo  
    A-Movie-I-love.jpg

    A-Movie-about-Llamas.avi  # :P 
    A-Movie-about-Llamas.nfo
    A-Movie-about-Llamas.jpg

into this:

Movies/: 

      A-Movie-I-love/:
           A-Movie-I-love.avi
           A-Movie-I-love.nfo
           A-Movie-I-love.jpg 

      A-Movie-about-Llamas/:
           A-Movie-about-Llamas.avi
           A-Movie-about-Llamas.nfo
           A-Movie-about-Llamas.jpg

right?

Last edited by lspci (2013-04-23 20:40:30)


Please don't be a help vampire. | Bitbucket

Give a little more for a little less today.  smile

Offline

#4 2013-04-23 20:37:57

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: bash script help?

Just use vidir with */* and a substitution command like this:

:%s_\t\([^/]*\)/[^.]*\._\t\1/\1.

In this case _ is the substitution argument delimiter.
It matches: TAB (used in file list by vidir), store pathname as pattern 1, path separator, filename with dot.
And replaces with: TAB, pathname (pattern 1), path separator, pathname (pattern 1) with dot.

Offline

#5 2013-04-23 20:56:17

pbhandari
Member
Registered: 2013-03-05
Posts: 8

Re: bash script help?

cd /path/to/movie/folder
for file in ./*; do
  cd "$file"
  [ `ls *.nfo | wc -l` -eq 1 ] && mv *.nfo "$file.nfo" || echo "multiple nfo: $file"
  [ `ls *.jpg | wc -l` -eq 1 ] && mv *.jpg "$file.jpg" || echo "multiple jpg: $file"
  [ `ls *.avi | wc -l` -eq 1 ] && mv *.avi "$file.avi" || echo "multiple avi: $file"
  cd "$OLDPWD"
done

perl-rename and/or sed can probably do this quicker, but ... I know how to do this with mvs ... so mvs it is.

also, notice how I'm just 'mv'-ing them ... If I screwed up somewhere(though I don't think, and I hope I haven't) you might end up losing your movies completely. So ... make sure you've got em backed up before running this.

Offline

#6 2013-04-24 08:51:17

ssl6
Member
From: Ottawa, ON, CA
Registered: 2007-08-30
Posts: 594

Re: bash script help?

@pbhandari

that worked perfectly for me.

I've never been able to wrap my head around the syntax's when it comes to scripting. I can work my way around the shell fine manually, and I can make out what that script is doing for the most part, but I've never been able to write those from scratch


this is a signature

Offline

#7 2013-04-24 15:13:03

pbhandari
Member
Registered: 2013-03-05
Posts: 8

Re: bash script help?

@ssl6

no problem, glad I could help.

Offline

#8 2013-04-25 22:17:58

deepsoul
Member
From: Earth
Registered: 2012-12-23
Posts: 57
Website

Re: bash script help?

pbhandari wrote:

also, notice how I'm just 'mv'-ing them ... If I screwed up somewhere(though I don't think, and I hope I haven't) you might end up losing your movies completely. So ... make sure you've got em backed up before running this.

Adding the "-i" option to the mv's might help make this safer.  Other than typing "n", you also get a chance to abort everything with Ctrl-C.


Officer, I had to drive home - I was way too drunk to teleport!

Offline

Board footer

Powered by FluxBB