Name: !L33tUKZj5I 2012-07-09 18:45
Hello,
Think I'll be able to figure this out eventually, but I've called it a day for now.
I have a folder that is so full of picture files, it takes forever to open in a normal file viewer. So I wanted to create a script that made a directory for each letter of the alphabet or number, then shift all the pictures that start with that letter or number into these directories, so that when I want to find a file I don't have to wait an ice age for the main folder to load and I can just click through to where I know it is.
I managed that part fine.
Some files though start with a space character, or a hyphen for some reason. I wanted to put these in a folder called "others".
These are giving me some gyp (other special characters seem to be fine so far) because when the ones that start with a space are fed into awk, awk works on fields so just starts from where the letters start instead of the space and doesn't strip out the proper filename. Fuck knows why "-" causes trouble too, I'm not really that versed in bash at all.
This is is the script anyway. It's the last line that isn't quite right...although it works fine for files that start with an underscore or an exclamation mark or something...
Fuck if I know what to do.
/prog/Think I'll be able to figure this out eventually, but I've called it a day for now.
I have a folder that is so full of picture files, it takes forever to open in a normal file viewer. So I wanted to create a script that made a directory for each letter of the alphabet or number, then shift all the pictures that start with that letter or number into these directories, so that when I want to find a file I don't have to wait an ice age for the main folder to load and I can just click through to where I know it is.
I managed that part fine.
Some files though start with a space character, or a hyphen for some reason. I wanted to put these in a folder called "others".
These are giving me some gyp (other special characters seem to be fine so far) because when the ones that start with a space are fed into awk, awk works on fields so just starts from where the letters start instead of the space and doesn't strip out the proper filename. Fuck knows why "-" causes trouble too, I'm not really that versed in bash at all.
This is is the script anyway. It's the last line that isn't quite right...although it works fine for files that start with an underscore or an exclamation mark or something...
#directory tidy program
exec 1>/dev/null 2>/dev/null;
# files starting lowercase
for count in {a..z}
do
mkdir $count;
mv "$count"* $count;
done;
# files starting uppercase
for count in {A..Z}
do
mkdir $count;
mv "$count"* $count;
done
#files starting with numbers
for count in {0..9}
do
mkdir $count;
mv "$count"* $count;
done
# special case files
mkdir others;
ls -n| grep -v ^d|awk '{print "mv \""$8"\" others"}'>tempfile.sh;chmod 777 tempfile.sh;./tempfile.sh;rm tempfile.sh;Fuck if I know what to do.