Walk the tree with topdown
set to False instead:
temp = os.walk(sys.argv[1], topdown=False)
for root, dirs, files in temp:
for i in dirs:
dir = os.path.join(root,i)
os.rename(dir, dir+"!")
From the documentation:
If optional argument topdown is True
or not specified, the triple for a directory is generated before the triples for any of its subdirectories (directories are generated top-down). If topdown is False
, the triple for a directory is generated after the triples for all of its subdirectories (directories are generated bottom-up).
Thus, you get to rename sub-directories first, and will see the top-level directories last, and renaming them will no longer affect how the sub-directories are found.
sys.argv[0]
like thattemp = os.walk('F:\\WORK\\ALGOCODE')
anddirs
list is empty. I am ok from doc with Martijn explanation. – Ducky