Thus spake Dave A. Peat II ([EMAIL PROTECTED]):
> Hello,
> I am moving a website from NT/IIS to UNIX. NT is not case
sensative, UNIX is. Can someone tell me of an easy way, possibly a
script or utility of some kind, to do two things:
> 1. Change all file names (some are uppercase and some are
lowercase) to ALL lowercase.
I've appended a Python script which I wrote a couple of years ago to
do exactly this and for eactly the same reason. (It also allows for
uppercasing names and initial capitalising if you wish) The script
could be improved, now that I'm more familiar with Python, but it does
work.
> 2. Change all tags within htm files (<A HREF=...>) that is, the
> path and file name , to lowerecase. For example, <A
> HREF="InfoSys/P_Directory/Index.htm"> to <A
> HREF="infosys/p_directory/index.htm">
I can't offhand recall how I did this at the time. sed perhaps?
--
|Deryk Barker, Computer Science Dept. | Music does not have to be understood|
|Camosun College, Victoria, BC, Canada| It has to be listened to. |
|email: [EMAIL PROTECTED] | |
|phone: +1 250 370 4452 | Hermann Scherchen. |
-------------------------------------------------------------------------------
#!/usr/local/bin/python
#
# Upper/lower case file names
#
import getopt
import glob
import os
import sys
import string
recursing = None # default is not to recurse
files = 1 # and to process files
directories = None # but not directories
verify = None # don't normally say what we're doing
# Now a dictionary mapping command
# names to functions
commands = {'icn': lambda x: string.upper (x[0]) + string.lower(x[1:]),
'lcn': string.lower,
'ucn': string.upper}
stdopts = 'fdarv' # options:
# -f files only
# -d directories only
# -a all (files and dirs)
# -r recurse
# -v verify
#
# Try to change a single name
#
def changeOneName (name, dir, file):
newname = os.path.join (dir, function (file))
if verify:
print "Renaming: ", name, " => ", newname
try:
os.rename (name, newname)
except:
sys.stderr.write (sys.argv[0] + ": cannot access " + name + "\n")
#
# Change case of all names. Test for inclusion of files and/or directories
# Recurse into subdirectories if necessary.
#
def changeName (name): # change case of name
dir, file = os.path.split (name)
if os.path.isdir (name): # a directory
if directories: # change its name?
changeOneName (name, dir, file)
if recursing: # recursing
names = glob.glob (name + "/*") # build list of names
for child in names:
changeName (child)
else: # not a directory
if files:
changeOneName (name, dir, file)
#
# Main code
#
if __name__ == '__main__':
try:
function = commands[sys.argv[0][-3:]]
except:
sys.stderr.write ("Usage icn|lcn|ucn [-adlrv] names\n")
sys.exit (1)
opts, args = getopt.getopt (sys.argv[1:], stdopts)
for opt, value in opts:
if opt == '-a':
files = directories = 1
elif opt == '-d':
files = None
directories = 1
elif opt == '-f':
files = 1
directories = None
elif opt == '-r':
recursing = 1
elif opt == '-v':
verify = 1
if not args:
sys.stderr.write ("Usage icn|lcn|ucn [-adlrv] names\n")
sys.exit (1)
for name in args:
changeName (name)