Register
It is currently Wed Aug 20, 2014 8:19 pm

scripts which moves all files in certain DIR on dir up.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Sat May 15, 2010 10:57 am   

Joined: Sat May 15, 2010 10:43 am
Posts: 8
Hi I'm trying to organise my data and currently I have a structure of my movies like this:

ls /home/adam/movies

Star.trek1
-CD1/Star.trek1-cd1.avi
-CD2/Star.trek1-cd2.avi
Star.trek2
-CD1/Star.trek2-cd1.avi
-CD2/Star.trek2-cd2.avi
Star.trek3
-CD1/Star.trek3-cd1.avi
-CD2/Star.trek3-cd2.avi

etc..

This has worked really well but now I'm starting to use XBMC and it likes to have all files of a movie in the same dir.

-Star.trek1
Star.trek1-cd1.avi
Star.trek1-cd2.avi


So I'm looking for a script that does this automatically:

./movefiles.sh /home/adam/movies/

This would go over all my movies and look for CD1 and CD2 directories and when it finds them, move all files in those directories one dir up to the movies "base" dir. If the movies doesnt have a CD1/CD2 dir, nothing should happen.

Also some of my movies are categories in subdirectories, like all star trek movies could all be inside a directory: /home/adam/movies/startrek/

So recursive search from base dir (./movefiles.sh /home/adam/movies/) would be great! :)

Maybe this is complicated, I'm new to scripting and programming in general but would love some help with this!! It would save me loads of time and I think it might help others aswell, as media centers only seem to grow and grow.

Thanks again, and if you have any questions please post here and I'll come back to you.


Top
 Profile  
 PostPosted: Sat May 15, 2010 7:53 pm   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
I dont have time right now to write this but I do suggest that instead of actually moving the files you create symlinks to them.


Top
 Profile  
 PostPosted: Sun May 16, 2010 3:10 am   

Joined: Sat May 15, 2010 10:43 am
Posts: 8
Hi, thanks for the reply but I'm looking for permanent movement. As this has to be compatible with samba and windows etc.., So I'd rather have them correctly placed physically. Again thanks for looking into it.


Top
 Profile  
 PostPosted: Sun May 16, 2010 7:29 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Code:
find -type d -name 'CD[0-9]' -exec echo mv {}/* {}/.. \; | bash

Then, you will have to remove the empty CD[0-9] directories. But, be careful! Moving files is dangerous, make sure you do not overwrite anything (at least, run the command without the "| bash" part to see what it's really going to do.)


Top
 Profile  
 PostPosted: Sun May 16, 2010 12:02 pm   

Joined: Sat May 15, 2010 10:43 am
Posts: 8
thanks!, I've changed CD1-9 to "CD?" so it takes everything from CD* but has to be 3 letters. could it be improved and make a rmdir CD? after the files has been moved?
if I use rmdir it only removes the dir if its empty so it should be relativly riskfree :)


Top
 Profile  
 PostPosted: Sun May 16, 2010 4:34 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Just use the same find, but instead of moving, remove:
Code:
find -type d -name 'CD?' -exec rmdir {} \;


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP