Page 1 of 1
Scripts and stuff
Posted: Wed Jun 13, 2007 6:26 pm
by wardrich
Since there are scattered posts all over the place about script files, I think it would be best to keep them all confined here from now on. Just to make it easier to follow it all. I'd split the other topics, but then all the posts and stuff would seem a bit out of place.
Posted: Wed Jun 13, 2007 8:14 pm
by wardrich
I'm currently trying to work on one that looks at all the files in $PWD and sorts them into ./music/ and ./pictures/ folders depending on their filetypes... And since I'm lazy and don't usually add extensions to my image files, it makes my life that much more fun. lol
Code: Select all
#/bin/bash
#Scattered Media Sorter Upper
if [ $(file "$i" | grep "image data") ]; then
mv "$i" pictures
fi
if [ $(file "$i" | grep "Audio file") ]; then
mv "$i" music
fi
I still have to add in the checks to see if ./music/ and ./pictures/ exists... and to make them if they don't.
Posted: Thu Jun 14, 2007 7:11 pm
by MiniMax
That is some bad coding there. Better use a case-construct:
Code: Select all
case "$(file "$i")" in
*"image data"* | *"bitmap data"* )
mv "$i" pictures/
;;
*"Audio file"* )
mv "$i" music/
;;
esac
Any fool can write code a computer can understand. It takes an expert to write code humans can understand
Posted: Thu Jun 14, 2007 8:51 pm
by wardrich
Yeah, thanks MiniMax. My script still wasn't working, so I knew stuff had to be done. I'm a total newb to Bash scripts. Thanks for the help
.