I don't know
cmd.exe, so I can't fix your script, but if you have Python installed, you can use this script (which should work on all OSes):
files = os.listdir('.')
for f in files:
newname = f.upper()
if newname == f:
if newname in files:
print( "error: %s already exists" % newname )
Just save it as
upcase_files_folders.py and then run
python upcase_files_folders.py in the directory whose files you wants to rename.
Update: Recursive solution.
Sorry, I just realized you wanted a recursive solution.
The following script will walk the subdirectory tree, recording the files and subdirectories to be renamed on a stack. Then it pops the files/subdirectories from the stack one by one and upcases them.
(A two-stage solution is best, to avoid renaming directories in the middle of the traversal. Trying to do it all at once is going to be error-prone and fragile.)
Also, it's probably best to keep a log of the changes in case you run the script in error. This script will record all renames in
from __future__ import print_function
with open('.upcase_files_folders.log','a') as logfile:
renames = 
for d, subdirs, fs in os.walk(os.getcwd()):
for x in fs + subdirs:
oldname = os.path.join(d, x)
newname = os.path.join(d, x.upper())
if x == '.upcase_files_folders.log' or newname == oldname:
for (oldname, newname) in reversed(renames):
print( "renamed: %s --> %s" % (repr(oldname), repr(newname)), file = logfile )