From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.help Subject: Re: Easy way to rename files sequentially? Date: Tue, 27 Nov 2007 16:14:47 +0100 Message-ID: <87ve7npvo8.fsf@thievol.homelinux.org> References: <87ejeexgfy.fsf@celephais.home.net> <871waeroap.fsf@newsguy.com> <8763zpwje7.fsf@newsguy.com> <87y7cl6uka.fsf@localhorst.mine.nu> <87ve7ox53v.fsf@newsguy.com> <87lk8ku5uz.fsf@thievol.homelinux.org> <87bq9gnp31.fsf@moley.moleskin.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1196176448 27926 80.91.229.12 (27 Nov 2007 15:14:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 Nov 2007 15:14:08 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Sebastian Tennant Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Nov 27 16:14:16 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ix28A-0003lt-4k for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Nov 2007 16:13:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ix27u-00061D-GJ for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Nov 2007 10:13:30 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ix27c-0005vU-E1 for help-gnu-emacs@gnu.org; Tue, 27 Nov 2007 10:13:12 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ix27Z-0005qn-V0 for help-gnu-emacs@gnu.org; Tue, 27 Nov 2007 10:13:11 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ix27Z-0005qO-Ky for help-gnu-emacs@gnu.org; Tue, 27 Nov 2007 10:13:09 -0500 Original-Received: from nf-out-0910.google.com ([64.233.182.188]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ix27Y-00017x-G5 for help-gnu-emacs@gnu.org; Tue, 27 Nov 2007 10:13:09 -0500 Original-Received: by nf-out-0910.google.com with SMTP id f5so941640nfh for ; Tue, 27 Nov 2007 07:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:to:cc:subject:references:face:date:in-reply-to:message-id:user-agent:mime-version:content-type:from; bh=mO/ErE45Ld7rPi7cTUlQ5YXpn38YKqpm0l3W7VDpSxI=; b=kqJ9d9zU2Xf5XPI61S6fXwnEmZgsdAumZ+Gm84pOm0hRx/aD0+mjSsNO+NAyLXx5uGGoTFtLBu11Zczg6jBEEjNVLFUWSw0Jtw4WKU5Id8Rez+ui3Lj0rX4GugN7qdIbptsWxGbAmmXf2JxSxH3onjkJg68PkrUFkJMXFWngsQQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:to:cc:subject:references:face:date:in-reply-to:message-id:user-agent:mime-version:content-type:from; b=G8BtN1BUJvRfS0BM/7MPSKD3daALzi6toWZzBB4y0RP0tSR2BT7vYP0uwZwRaN0V0URI5PgWEgP9nE7ItBIrOZ9/ebUrgW9eERC0c/MPACYOVA9uYrMfmqXL4/cjlt62cZA4F53b30E9Jpq219j872FuQTmpXJn3/1M4KoKfdgo= Original-Received: by 10.86.60.7 with SMTP id i7mr3937320fga.1196176386766; Tue, 27 Nov 2007 07:13:06 -0800 (PST) Original-Received: from thievol.homelinux.org ( [79.81.52.48]) by mx.google.com with ESMTPS id l12sm1649994fgb.2007.11.27.07.13.04 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Nov 2007 07:13:05 -0800 (PST) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAHlBMVEUAAAD/eiojJC8HDgL9 q6CxcyAADQCPoKCbKDEHHjqGqpmkAAACZklEQVQ4jWVTwW7TQBAdZSSL61Jb8jFyVSXcth5inKPF RvSImwTtMSKSPwCoLG44xtKeyal/y9sN1G47x3meN7PvPdNZEzVNQzwTYhGtz8I6EnSJtUQHotni nWYSNA5ciFARkIK0Xvx8LBpmKRppDgyaI+YifLduf54bmpPkgQj0fp6Z1237XTTLyphtoanR4ktr Wv9p27kw7+xQ/WpI+LcxqcYOzhbtJ4x0tjNb0KxMUsdXOc7K2odsHvHK1upOSGLrXFdhZIZR84W4 BJBoKpVDxR9FBvSrnjnfd0ppulW+YuN2CYDNFu8fag90vm8HZSq1aX/sLS50ygO+n4qAVrk26+pU S+c7AehzKfvBnrLM2fi+BNNbodtKpXgudtus/VamXeU/3TKVddpDbxCc1o/nslr6fjKn4AEkI1Gn PJOhwjal7kPrUhKn17LcVbIKq8di3LWssU+cu6Zp3cQVtOg11GYINOEaIE3v/WQ9HeAPldr30TEk Y1rvoYnNF3O+ZOZpiCFm0gPwZh9IRrayUm5nHj4TFxgRfgJm0HQ/mHsfDSyZ7C9NEENk6YTlcbzq pg6WbSHezsp6BIYLcHej3D7ejKKsrPeyU8kN+ICPK4KVXZdmYTIdFYHzKlVpfwgpSMYdy770KdgW pUf6iVgS2DbIl0JWJoAuA3ttKifRREjNF6BLeqHjFIi+eiCxIs/8gKpHHx343fAzLGqOiA5iLi+c wj+ZIwcswZBJ+Zin7jqwPANY8h1+h+00U6HPOsdV5opelrDXwvTRK2C2dC/S+e/cN9bV6vQawA+R 1Fa/7vtXIAb/c/MXBLaluuFkJS8AAAAASUVORK5CYII= In-Reply-To: <87bq9gnp31.fsf@moley.moleskin.org> (Sebastian Tennant's message of "Tue\, 27 Nov 2007 09\:07\:46 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49582 Archived-At: --=-=-= Sebastian Tennant writes: > Quoth Thierry Volpiatto : >> I would like to do some thing like that: >> >> (shell-command "~/bin/serialrename.py -d dir -e txt")) > > I believe what you want can be achieved like this: > > (shell-command (format "~/bin/serialrename.py -d %s -e txt" dir)) > Thank you again, i did that, it work fine :) (setq serial-rename-command "~/bin/serialrename.py") (defun tv-serial-rename (dir ext name start) (interactive "sDir: \nsExt: \nsName: \nsStart: ") (find-file dir) (shell-command (format "%s -d %s -e %s -n %s -s %s" serial-rename-command dir ext name start))) Ci joint le script python: --=-=-= Content-Type: text/x-python Content-Disposition: inline; filename=serialrename.py Content-Description: script python #!/usr/bin/python # -*- coding: utf-8 -*- # $Id: serialrename.py,v 1.5 2007/11/27 15:05:06 thierry Exp $ #commentary: #Rename the content of a directory #+with incremental numbers #+ for a specific extension file import os from optparse import OptionParser import sys parser = OptionParser() parser.add_option("-d", "--dir", dest="rep", help ="Input directory(with / at the end please)") parser.add_option("-n", "--name", dest="nom", default="file", help ="optional:file name") parser.add_option("-s", "--start-number", dest="startn", default=101, help ="optional:initial incremental number") parser.add_option("-e", "--ext", dest="extension", help ="file type - ex: jpg(without dot)") (options, args) = parser.parse_args() rep = options.rep nom = options.nom startn = int(options.startn) extension = options.extension if len(sys.argv) < 3: parser.error("Serialrename take at list 2 arguments\n you must specify options -d and -e") else: try: dir_photos = os.listdir(rep) for i in dir_photos: if extension in i: new = rep + nom + str(startn) + "." + extension if new not in dir_photos: print new os.rename(rep + i, new) startn += 1 else: print new, "new" os.rename(rep + i, new + "new") startn += 1 except (IOError, TypeError): raise "Check the path of your dir - Have you forget the / at the end ?" --=-=-= -- A + Thierry --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ help-gnu-emacs mailing list help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --=-=-=--