Scripts and stuff

Discuss popular GCS tools like ZZT, Megazeux and Adventure Game Studio, as well as programming and other topics related to game design.
Post Reply
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Scripts and stuff

Post 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.
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post 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.
User avatar
MiniMax
Expert
Expert
Posts: 149
Joined: Thu Jan 25, 2007 8:03 am
Location: Stockholm, Sweden

Post 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
DOSBox ReadMe | DOSBox Wiki | DOSBox 60 seconds guide | How to ask questions
_________________
Shuttle SN41G2 | Athlon XP 2600+ | IGP@128 MB | NEC 3520A DVD | Win XP Home/SP2
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post 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 :).
Post Reply