我的代码有问题。我对Python还不熟悉,但我正在尝试编写一个脚本来重命名文件夹(子文件夹)中超过3年的所有文件。
它对文件夹中的文件很好,但是当它涉及到子文件夹中的文件时,我得到一个“找不到文件”的错误。在
这是我的代码:import sys, os.path, time, datetime
count = 0
for (dirname, dirs, files) in os.walk('.'):
for filename in files:
thefile = os.path.join(dirname,filename)
today = datetime.datetime.today()
modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(thefile))
duration = today - modified_date
if duration.days > 1095:
old = filename
new = 'old_' + old
print(thefile, "Last modified: %s" % time.ctime(os.path.getmtime(thefile)), os.path.getmtime(thefile))
count = count + 1
os.renames(old, new)
print("number of old files: ", count)
有人能帮我吗?在