Yes, I'm still alive. I'd love to say I haven't been blogging because I've been engaged in some sort of exceitment, but to tell the truth I just haven't felt like it. Work isn't going so well for me right now and it was nice to just vegetate all weekend and not think about it. Now that it's only a few hours away I guess I'm here blogging to get my mind off things. I actually wrote a couple of posts on the subject but I didn't want this place to start looking like the livejournal of some confused teenager so I didn't post them.

But lookie! I do have something to contribute to all you good ole folks out there on tha interweb.

Say you have a directory filled with directories that are filled with files of some sort. This script will move them all to wherever you want and rename them to the name of the directory they came from plus a sequential number. In my case I had a directory for digital camera photos called "pics" and inside were directories such as "August19" and "July9" and inside those were files named dscf0001.jpg and dscf0001.jpg ... etc. I couldn't just go into every directory and move them because all the directories had files of the same name. I had to rename them all first.

If I cd into "pics" and run this script it moves all the images to one directory and renames them August19-1.jpg August19-2.jpg August19-3.jpg July9-1.jpg July9-2.jpg July9-3.jpg ... etc.

When you run it, it asks for the file type and the location to move them to, which it will create if you want.


echo "File type?"
read files
echo "Location to move them to?"
read location
echo "type c to create that directory or enter to continue"
read -n 1 -s YorN
if [ "$YorN" = "c" ]; then
mkdir $location
else echo

for i in `ls -F | grep \/ | perl -pi -e "s/\///g"`
# echo dir $i >> $0
cd $i

NAME=`basename $PWD2`

for i in `ls *.$files`
mv $i "$NAME"-"$COUNT".$files
COUNT=`expr $COUNT + 1`


mv *.$files $location


<< Home

This page is powered by Blogger. Isn't yours?