LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script to sort video files into different folders (https://www.linuxquestions.org/questions/linux-general-1/script-to-sort-video-files-into-different-folders-4175438010/)

MidKnightLoki 11-20-2012 03:05 PM

Script to sort video files into different folders
 
I have a downloads folder that gets many different files from different sources (mostly videos) I am also using XBMC as my Media Center I am trying to create a script that will move all related files to the same folder.

Ex. ~/Videos folder may contain a file called My.Show.s04e06.mkv
in the same folder there may be another file called myshows04e07.avi

I would like both of the above files to go to a folder called ~/Videos/Shows/MyShow so that it will be easy to find in XBMC

I have been using Bash and various combinations of ls, find, and mv commands but I cant seem to get it it to work.

I am fairly new to Linux but I do have some basic knowledge of scripting and programming so I am just looking for someone to point me in the right direction.

Thanks

unSpawn 11-20-2012 05:49 PM

Code:

#!/bin/sh --
find ~/Videos -type f \( -iname \*.mkv -o -iname \*.avi -o -iname \*.m4v -o -iname \*.divx -o -iname \*.mpg -o -iname \*.flv -o -iname \*.mov -o -iname \*.wmv -o -iname \*.3gp \) -print0 | xargs -0 -iX mv 'X' ~/Videos/Shows/MyShow
exit 0

Next time please post what you got instead of saying "doesn't work". Existing (pseudo) code shows you've tried, making improving it both efficient and a learning experience.


All times are GMT -5. The time now is 05:30 PM.