#改变文件夹修改时间为当前时间
import os
path = r"" #文件夹目录
def changeDay(path): #在最后写入一个字符并删除
with open(path, "a") as f:
f.write("1")
with open(path, "rb+") as f:
f.seek(-1, os.SEEK_END)
f.truncate()
def getAlldirInDiGui(path):
filesList=os.listdir(path) #列出当前路径下所有文件
print(filesList)
for fileName in filesList: #遍历当前路径下所有文件
fileAbpath=os.path.join(path,fileName)
if os.path.isdir(fileAbpath): #如果是目录
#print("目录:" ,fileName)
getAlldirInDiGui(fileAbpath)
else:
#print("普通文件",fileName)
changeDay(fileAbpath)
getAlldirInDiGui(path)
博采众长了属于是
参考:python 递归读取文件_python递归读取文件-CSDN博客Python快速删除文本最后一行/删除最后N行/删除后N个字符_python 删除文件倒数几行-CSDN博客