spaces at ends of filenames or directory names on Win32
rtilley
rtilley at vt.edu
Mon Feb 27 10:55:28 EST 2006
drobinow at gmail.com wrote:
> Please post your Python code. I don't see the problem you're
> describing.
OK, here's a copy. This works on Mac/Unix/Linux yet has no effect on
Windows:
-----------------------------------------------------------------
import os
import os.path
for root, dirs, files in os.walk(os.getcwd()):
for d in dirs:
new_d = d.strip()
## Uncomment the next 4 lines just to print dirs with end spaces.
## if new_d != d:
## print d
## else:
## print "No end spaces."
## Uncomment the next 7 lines to try a rename of dirs with end spaces.
## if new_d != d:
## try:
## new_path = os.path.join(root, new_d)
## old_path = os.path.join(root, d)
## os.renames(old_path, new_path)
## except Exception, e:
## print e
------------------------------------------------------------------
More information about the Python-list
mailing list