File: class/Extras/Other/_old-Tools/packaging/Scripts/fixnames_all2.py
#########################################################
# Use: "python ..\..\Tools\fixnames_all2.py".
# find all files with all-upper-case names at
# and below current directory ('.'); for each, ask
# the user for a new name to rename the file to;
# this version uses the os.path.walk interface,
# rather than doing a find to collect names first;
# to make this work like the simple find version,
# we need to rename directories after we've already
# descended into them (skipped over on files list);
# note: this version visits 1 extra file (the topmost
# root dir), and visits dirs in a diffferent order;
# both versions run in < 1sec on my typical dir trees;
#########################################################
import os
listonly = 0
from fixnames_all import convertOne
def visitname(fname):
global ccount, vcount
print vcount+1, '=>', fname
if not listonly:
ccount = ccount + convertOne(fname)
vcount = vcount + 1
def visitor(myData, directoryName, filesInDirectory): # called for each dir
visitname(directoryName) # do dir we're in now,
for fname in filesInDirectory: # and non-dir files here
fpath = os.path.join(directoryName, fname) # fnames have no dirpath
if not os.path.isdir(fpath):
visitname(fpath)
ccount = vcount = 0
os.path.walk('.', visitor, None)
print 'Converted %d files, visited %d' % (ccount, vcount)