From owner-freebsd-questions@FreeBSD.ORG Mon Jan 4 19:14:11 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8A9AF1065694 for ; Mon, 4 Jan 2010 19:14:11 +0000 (UTC) (envelope-from fbsd.questions.list@gmail.com) Received: from mail-ew0-f226.google.com (mail-ew0-f226.google.com [209.85.219.226]) by mx1.freebsd.org (Postfix) with ESMTP id 19D8F8FC1E for ; Mon, 4 Jan 2010 19:14:10 +0000 (UTC) Received: by ewy26 with SMTP id 26so13418636ewy.3 for ; Mon, 04 Jan 2010 11:14:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=57IXoX2eUHdU6/m1YUM1AI7CiMgfuKKU2Dey6AzYEss=; b=g8pXFW6D0mzPmyh+Ic+MvUGTQJcUp0oBEtpWC1+zITVp8apeWVBbFVY9ZCzSRBP5YT P2MmvJg+Yl403mZAIRd24OiAF8waqRbF5Pb+kWZflnLuxjSmFCG1ONbMqyZxMb3eY/Qn QwJhotZazAAIDHOXkwzGTOAlSnTuZwERzzF+A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=Tlt9doN13Z00CrGyRCPod615lRuynQ01XVFIgjzXNxZ9hPltYHC3RNSkJn1c5w1vDu 4Z7uzhvezh1NK+ET+8x7yzYW8BLbR5ymMun8z6AcpCk8I+22nYi73CEaZIVi5VaN7JoK 4KZV51ip+Lfh4NIt07F0/pq6ie9fTt/VQyI3E= Received: by 10.213.2.67 with SMTP id 3mr25672166ebi.77.1262632441694; Mon, 04 Jan 2010 11:14:01 -0800 (PST) Received: from ?192.168.2.2? (ip4da86a9a.direct-adsl.nl [77.168.106.154]) by mx.google.com with ESMTPS id 5sm37615210eyh.24.2010.01.04.11.13.59 (version=SSLv3 cipher=RC4-MD5); Mon, 04 Jan 2010 11:14:01 -0800 (PST) From: =?ISO-8859-1?Q?D=E1rio?= "P." To: Polytropon In-Reply-To: <20100104191610.5054255f.freebsd@edvax.de> References: <1262624558.9656.16.camel@dasp-laptop> <20100104191610.5054255f.freebsd@edvax.de> Content-Type: text/plain; charset="UTF-8" Date: Mon, 04 Jan 2010 20:13:57 +0100 Message-ID: <1262632437.11494.18.camel@dasp-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 8bit Cc: freebsd-questions@freebsd.org Subject: Re: Rename pictures in the command-line interface X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jan 2010 19:14:11 -0000 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 ". It will process ALL > files in the current directory (as I said: ugly as sin). > > > #!/bin/csh > if ( $1 == "" || $2 == "" ) then > echo "Usage: renumber " > echo " Target form: _nn[n]." > 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. :)