worldroll
March 28th, 2011, 07:19 PM
This is my first script, which I freely admitting to assembling via cut and pasting from various google searches.
Basically I wanted a script to unpack scene image packs from the form of
something.com_11.02.01.blah/blah00.zip
something.com_11.02.01.blah/blah01.zip
something.com_11.02.01.blah/blah02.zip
where each zip is of the form
blah00.zip/file_id.diz
blah00.zip/blah.nfo
blah00.zip/blah.rar
to
something.com/something.com_11.02.01.blah/aa01.jpg
something.com/something.com_11.02.01.blah/aa02.jpg
something.com/something.com_11.02.01.blah/aa03.jpg
something.com/something.com_11.02.01.blah/aa04.jpg
What I have done seems to be working so far when the files are fine and the file nameing is as expected. What I would like to do is the make it a bit more robust, so that it gives error messages yet, so any feedback on how to make it better are more then welcome :D
#! /bin/bash
#Script to unpack sceen releases
#unzip all zip files
for i in `find . -name "*.zip"`; do unzip -o -d `dirname $i` $i;done;
#delete all zip files
for i in `find . -name "*.zip"`; do rm $i;done;
#unrar recusively
find ./* -type f -name '*.rar' -execdir unrar x {} \;
#remove rar
for i in `find . -name "*.r??"`; do rm $i;done;
#remove sample folder
for i in `find . -name "Sample"`; do rm -r $i;done;
#print list of all folders
ls -d */ > dirlist.txt
#keep just the site name
sed 's/_.*//g' dirlist.txt > dirlist2.txt
#remove duplicate entries
cat dirlist2.txt|uniq > dirlist3.txt
#make directories
for d in $(cat dirlist3.txt); do mkdir $d; done
#move directors
for d in $(cat dirlist3.txt); do mv $d?* $d; done
Basically I wanted a script to unpack scene image packs from the form of
something.com_11.02.01.blah/blah00.zip
something.com_11.02.01.blah/blah01.zip
something.com_11.02.01.blah/blah02.zip
where each zip is of the form
blah00.zip/file_id.diz
blah00.zip/blah.nfo
blah00.zip/blah.rar
to
something.com/something.com_11.02.01.blah/aa01.jpg
something.com/something.com_11.02.01.blah/aa02.jpg
something.com/something.com_11.02.01.blah/aa03.jpg
something.com/something.com_11.02.01.blah/aa04.jpg
What I have done seems to be working so far when the files are fine and the file nameing is as expected. What I would like to do is the make it a bit more robust, so that it gives error messages yet, so any feedback on how to make it better are more then welcome :D
#! /bin/bash
#Script to unpack sceen releases
#unzip all zip files
for i in `find . -name "*.zip"`; do unzip -o -d `dirname $i` $i;done;
#delete all zip files
for i in `find . -name "*.zip"`; do rm $i;done;
#unrar recusively
find ./* -type f -name '*.rar' -execdir unrar x {} \;
#remove rar
for i in `find . -name "*.r??"`; do rm $i;done;
#remove sample folder
for i in `find . -name "Sample"`; do rm -r $i;done;
#print list of all folders
ls -d */ > dirlist.txt
#keep just the site name
sed 's/_.*//g' dirlist.txt > dirlist2.txt
#remove duplicate entries
cat dirlist2.txt|uniq > dirlist3.txt
#make directories
for d in $(cat dirlist3.txt); do mkdir $d; done
#move directors
for d in $(cat dirlist3.txt); do mv $d?* $d; done