catsquotl writes:
I have already renamed the few names that had ordinary names there is
a huge number of files beginning with F followed by a number. I`d like
to automaticaly change all of these to f.
Hi, people.
I have been doing such things regularly for a long while now. Since I
converted many of my Perl scripts to Python rather recently, I thought
I had a nice Python solution for you. Sadness! I found out that I was
still using a mix of shell and `awk' scripts for this. Good opportunity
for me to undust that corner: I added proper processing for more deeply
nested files, and clash detection at `rename' time.
Here is a `lofn' script (to be installed as an executable on your PATH).
---------------------------------------------------------------------->
#!/usr/bin/env python
# Copyright © 1990, 2000 Progiciels Bourbeau-Pinard inc.
# François Pinard , October 1990.
"""\
Convert upper case in file names to lower case.
Usage: lofn [OPTION]... [FILE]...
-n just say what would be done, without doing it
-v be verbose about what is being done
"""
import getopt, os, string, sys
def main(*arguments):
if not arguments:
sys.stdout.write(__doc__)
sys.exit(0)
options, arguments = getopt.getopt(arguments, 'nv')
dryrun = verbose = 0
for option, value in options:
if option == '-n':
dryrun = verbose = 1
elif option == '-v':
verbose = 1
for old_name in arguments:
directory, base = os.path.split(old_name)
new_name = os.path.join(directory, string.lower(base))
if new_name != old_name:
if os.path.exists(new_name):
sys.stderr.write("# `%s' would clash with `%s', not renamed\n"
% (old_name, new_name))
else:
if verbose:
sys.stderr.write('mv %s %s\n' % (old_name, new_name))
if not dryrun:
os.rename(old_name, new_name)
if __name__ == '__main__':
apply(main, tuple(sys.argv[1:]))
----------------------------------------------------------------------<
Here is one way you could use it for your precise case (untested), presuming
you are using GNU `find' and `xargs':
find DIRECTORY -regex '.*/F[0-9]*' | xargs -r lofn
--
François Pinard http://www.iro.umontreal.ca/~pinard
--
To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com
For additional commands send e-mail to suse-linux-e-help@suse.com
Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/