Trivial (NT) administrative script for the lazy 
Author Message
 Trivial (NT) administrative script for the lazy

Well, I found myself needing (yet again) to rename all the files in an
NT file hierarchy to their lowercase equivalents.  No problem, just
write a little script to use os.walk, os.path.rename, and
string.lower, right?  Well, yes, but why rewrite the thing every time
you find your web-site gunked up by some old DOS programme.  Hence,
this little script:

'''
Utility module for renaming all files in an hierarchy to lowercase.

Provided for your information only, no warranties, no guarantees, do
not use this unless you are willing to accept whatever consequences
might arise from using it.
'''

import os
import string
import sys

def rename_by_function(path_processing_function, directoryname,
filenames):
        try:
                os.rename(directoryname,
path_processing_function(directoryname))
        except:
                sys.stderr.write('Unable to rename directory
%s\n'%directoryname)
        for fname in filenames:
                filename = string.join((directoryname,fname),os.sep)
                try:
                        os.rename(filename,
path_processing_function(filename))
                except:
                        sys.stderr.write('Unable to rename file
%s\n'%filename)

if __name__ == '__main__':
        try:
                if sys.argv[1] in ('-lower','-l'):
                        func = string.lower
                        nm = sys.argv[2:]
                elif sys.argv[1] in ( '-upper','-u'):
                        func = string.upper
                        nm = sys.argv[2:]
                else:
                        func = string.lower
                        nm = sys.argv[1:]
        except IndexError:
                sys.stderr.write(usage)
                nm = []
        try:
                for name in nm:
                        os.path.walk(name, rename_by_function,func)
        except:
                sys.stderr.write('''Critical error encountered while
walking the directory tree %s\n'''%nm)
        sys.stderr.write('''Exiting.\n''')

Enjoy!
Mike
________________________________
 M i k e   C .  F l e t c h e r


http://www.*-*-*.com/ ~mcfletch/
________________________________
 Design, Consultation, Training



Sat, 01 Apr 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. NT administrative scripts, anyone ?

2. Python COM installation and NT Administrative rights.

3. Trivial question about exec'ing a shell script

4. Expect script problem (should be trivial)

5. trivial Expect script has me stumped

6. lazy.py 0.7 - Lazy expressions and datastructures

7. How lazy is lazy?

8. lazy (non-eager) Scheme ??? (lazy, but eager me)

9. lazy.dylan 0.1 -- add ML/Scheme-style lazy evaluation to Dylan

10. lazy.py 0.7 - Lazy expressions and datastructures

11. lazy (non-eager) Scheme ??? (lazy, but eager me)

12. LOGO-L> Administrative announcement

 

 
Powered by phpBB® Forum Software