Date: Mon, 04 Jan 2010 20:13:57 +0100 From: =?ISO-8859-1?Q?D=E1rio?= "P." <fbsd.questions.list@gmail.com> To: Polytropon <freebsd@edvax.de> Cc: freebsd-questions@freebsd.org Subject: Re: Rename pictures in the command-line interface Message-ID: <1262632437.11494.18.camel@dasp-laptop> In-Reply-To: <20100104191610.5054255f.freebsd@edvax.de> References: <1262624558.9656.16.camel@dasp-laptop> <20100104191610.5054255f.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Seg, 2010-01-04 às 19:16 +0100, Polytropon escreveu: > Keep in mind that the script follows the csh's sorting > order to resolve *, which usually is lexicographical > order. The sorting order is not a big problem for me, at least for now. I'm doing the renaming in one machine with GUI then I upload the pictures to another machine. The only reason that I need this, is because sometimes I delete one picture on the other machine and then I have to rename everything again. > So if you wish to do some file preparation, know that the > powerful Midnight Commander can do this for you (select and > PF6). Anyway, I gonna look at it. > Here's the script now. Put it in ~/bin (and add this directory > to your $PATH) as "renumber" (or any name you like), give it +x > permissions and "rehash" to make it available to the C shell. > Then, use "renumber <prefix> <suffix>". It will process ALL > files in the current directory (as I said: ugly as sin). > > > #!/bin/csh > if ( $1 == "" || $2 == "" ) then > echo "Usage: renumber <base> <extension>" > echo " Target form: <base>_nn[n].<extension>" > echo " For 1 to 99 files: nn; for more than 99 files: nnn" > exit 1 > endif > > set n = `ls -l | wc | awk '{print $1}'` > set num = `expr $n - 1` > echo "${num} files to handle." > > set base = $1 > set extn = $2 > set n = 0 > foreach f ( *.${extn} ) > set n = `expr $n + 1` > if ( ${num} > 99 ) then > if ( ${%n} == 1 ) then > mv "${f}" "${base}_00${n}.${extn}" > else if ( ${%n} == 2 ) then > mv "${f}" "${base}_0${n}.${extn}" > else > mv "${f}" "${base}_${n}.${extn}" > endif > else > if ( ${%n} == 1 ) then > mv "${f}" "${base}_0${n}.${extn}" > else > mv "${f}" "${base}_${n}.${extn}" > endif > endif > end > > Thanks alot. :)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1262632437.11494.18.camel>