From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: Sebastian Tennant <sebyte@smolny.plus.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Easy way to rename files sequentially?
Date: Tue, 27 Nov 2007 16:14:47 +0100 [thread overview]
Message-ID: <87ve7npvo8.fsf@thievol.homelinux.org> (raw)
In-Reply-To: <87bq9gnp31.fsf@moley.moleskin.org> (Sebastian Tennant's message of "Tue\, 27 Nov 2007 09\:07\:46 +0200")
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
Sebastian Tennant <sebyte@smolny.plus.com> writes:
> Quoth Thierry Volpiatto <thierry.volpiatto@gmail.com>:
>> 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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: script python --]
[-- Type: text/x-python, Size: 1778 bytes --]
#!/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 ?"
[-- Attachment #3: Type: text/plain, Size: 17 bytes --]
--
A + Thierry
[-- Attachment #4: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
next prev parent reply other threads:[~2007-11-27 15:14 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-25 19:39 Easy way to rename files sequentially? cothrige
2007-11-25 20:35 ` Sven Bretfeld
2007-11-25 21:12 ` Eli Zaretskii
2007-11-25 21:46 ` reader
2007-11-26 3:39 ` Eli Zaretskii
2007-11-26 7:33 ` reader
2007-11-26 12:49 ` David Hansen
2007-11-26 17:56 ` reader
2007-11-26 18:26 ` David Hansen
2007-11-26 20:40 ` Eli Zaretskii
[not found] ` <mailman.4145.1196109649.18990.help-gnu-emacs@gnu.org>
2007-11-26 21:00 ` David Kastrup
2007-11-26 20:08 ` Thierry Volpiatto
2007-11-27 7:07 ` Sebastian Tennant
2007-11-27 7:18 ` Thierry Volpiatto
2007-11-27 15:14 ` Thierry Volpiatto [this message]
2007-11-27 15:20 ` Sebastian Tennant
2007-11-26 20:03 ` Eli Zaretskii
2007-11-27 19:31 ` reader
[not found] ` <mailman.4195.1196192427.18990.help-gnu-emacs@gnu.org>
2007-11-27 20:12 ` Joel J. Adamson
2007-11-27 21:35 ` Thierry Volpiatto
2007-11-27 22:00 ` Joel J. Adamson
[not found] ` <mailman.4203.1196200844.18990.help-gnu-emacs@gnu.org>
2007-11-27 23:40 ` Johan Bockgård
2007-11-27 23:43 ` David Kastrup
2007-11-28 15:27 ` Joel J. Adamson
[not found] ` <mailman.4117.1196081659.18990.help-gnu-emacs@gnu.org>
2007-11-28 4:17 ` cothrige
2007-11-28 6:43 ` Thierry Volpiatto
2007-11-28 14:27 ` Ted Zlatanov
2007-11-28 15:35 ` Joel J. Adamson
2007-11-28 17:18 ` cothrige
2007-11-28 21:20 ` cothrige
[not found] ` <mailman.4107.1196062436.18990.help-gnu-emacs@gnu.org>
2007-11-28 3:48 ` cothrige
2007-11-25 21:19 ` Xah Lee
2007-11-25 22:40 ` reader
2007-11-25 23:16 ` Peter Dyballa
2007-11-25 23:50 ` reader
2007-11-26 9:20 ` Peter Dyballa
2007-11-26 18:11 ` reader
2007-11-26 22:23 ` Peter Dyballa
2007-11-27 19:28 ` reader
2007-11-25 21:51 ` Peter Dyballa
2007-11-25 23:34 ` reader
2007-11-25 23:11 ` Bastien
[not found] ` <mailman.4087.1196027477.18990.help-gnu-emacs@gnu.org>
2007-11-28 3:36 ` cothrige
[not found] ` <mailman.4081.1196022933.18990.help-gnu-emacs@gnu.org>
2007-11-29 3:29 ` cothrige
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ve7npvo8.fsf@thievol.homelinux.org \
--to=thierry.volpiatto@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=sebyte@smolny.plus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.