[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Renaming files



Sorry for the length of this thought I should be VERY clear as to the
limited scope of what I'm doing.

Bob,  I use mmv out of habit. It does more than mv and I've used those
functions in the past -- rather than try to remember which functions
mv does not do.

OK -- when I followed up on that old thread about renaming files I
didn't specify WHY I wanted to do it. It's from a thread I started in
the procmail-users list.

Thanks for all the various ideas. I'm staying with the for-loop for
simplicity's sake and because this will never see that many files.

What I am doing is setting up a way for the net-idiot type users of a
Volkswagen related list I am on to post images without them having to
learn html, find a host, or resort to pop-up laden free hosts. No
attachments allowed to the list and I'm all for that, it's email. This
started because the listmaster was considering going to a web-forum
setup so images could be displayed. I would drop membership. I'm a
member because the email comes to me, i don't have to remember to log
in at some web page every few days, nor am I forced to use a graphical
interface if I don't want to.

I got my procmail/metamail difficulties worked out. If an email is
sent to a specific address I have set up then procmail grabs it.
Procmail saves the original headers in a temporary folder then passes
it to metamail. Metamail takes out the mime parts and saves those. It
saves the message body using a random name it generates and saves any
other attachments with the names indicated in the mime parts.

I am ONLY worried about gif, jpg, and bmp files. I don't care about
other files and won't make them available. Below is the short script I
have working to handle the graphic files and create a text file of
links to their future web location. All directories cleaned so it
looks like it's all in /, but it's not (to reduce wrapping, I'm bad
about long one-liners).

I still have to add a bit to transfer the files to a web location when
that is determined and use 'mail' to generate a message back to the
list that contains the original text body of the message, the 'links'
that were generated, and the name of the original sender. Since I
can't seem to control the name that metamail uses for the saved text
part I'll probably have to shift the known entities (graphic files and
link text file) to another directory then 'cat' whatever is left inth
the email text. Except, if some other file type is attached that will
get tossed back in also -- ick.

Also note the use of 'convert' to shrink bmp files by converting them
to jpg -- love it when a WIN using friend sends me a 900K bmp that
could have been a 100K jpg.

The script:cat ~/bin/names

#!/bin/bash

typeset -i a=1

if [ `ls /t/*.jpg 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.jpg;
   do mmv "$i" /t/`date +%s`-$a.jpg; a=a+1; done
 if [ `ls /t/*.JPG 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.JPG;
   do mmv "$i" /t/`date +%s`-$a.jpg; a=a+1; done
 fi
fi

if [ `ls /t/*.gif 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.gif;
   do mmv "$i" /t/`date +%s`-$a.gif; a=a+1; done
 if [ `ls /t/*.GIF 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.GIF;
   do mmv "$i" /t/`date +%s`-$a.gif; a=a+1; done
 fi
fi

if [ `ls /t/*.bmp 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.bmp;
   do mmv "$i" /t/`date +%s`-$a.bmp; a=a+1; done
 if [ `ls /t/*.BMP 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.BMP;
   do mmv "$i" /t/`date +%s`-$a.bmp; a=a+1; done
 fi
fi

if [ `ls /t/*.bmp 2>/dev/null|wc -l` -gt 0 ]
  then for i in /t/*.bmp;
   do convert "$i" `basename "$i" .bmp`.jpg; rm -f "$i"; done
fi

if [ `ls /t/*.jpg 2>/dev/null|wc -l` -gt 0 ]
 then for i in /t/*.jpg;
  do echo "http://host.com/images/$i"; >>/t/links; done
fi

if [ `ls /t/*.gif 2>/dev/null|wc -l` -gt 0 ]
 then for i in /t/*.gif;
  do echo "http://host.com/images/$i"; >>/t/links; done
fi



-- 
Gerald
http://www.phorce1.com
http://www.buskatiers.org



Reply to: