How to recursively walk directory & rename files & directories with Python 3.1 on windows?
#!c:/Python31/python.exe -u
import os
path = "test"
for (path, dirs, files) in os.walk(path):
print (path)
print ("-----------------")
if "monitoring" in path:
dst = path.replace("monitoring", "managing", 10)
print (dst)
os.rename(path, dst)
print ("path----")
for file in files:
if "hw" in file:
print (file)
dst = file.replace("hw", "hw2", 10)
os.rename(file, dst)
print (dst)
print ("file----")
My test program has this error:
Traceback (most recent call last):
File "C:\python\pathwalk.py", line 17, in <module>
os.rename(file, dst)
WindowsError: [Error 2] The system cannot find the file specified