[Python] 纯文本查看 复制代码import datetime
import os
def main(filename_pre, fileauthor, filetype_pre):
# print(filetype_pre)
path = r'./' # 路径为当前文件夹
filelist = os.listdir(path) # 该文件夹下所有的文件(包括文件夹)
for files in filelist: # 遍历所有文件
Olddir = os.path.join(path, files) # 还是原来的文件路径
if os.path.isdir(Olddir):
continue # 如果是文件夹则跳过
else: # 反之,则继续
# print(Olddir)
filenamepre = str(Olddir) # 转化为字符串
filenamepre = filenamepre.replace("[", "").replace("]", "").replace("'", "").replace(",", "\n").replace(" ","").replace( "./", "") # replace替换"["、"]"、" "、"'" "./"
firstname = os.path.splitext(filenamepre)[-2] # 文件名
lastname = os.path.splitext(filenamepre)[-1] # 文件后缀
if filename_pre == '':
filename = str(str(firstname).split('_')[0]) # 依据“_”对文件名拆分获取文件名
else:
filename = filename_pre
# print(str(filename))
# print(firstname)
# print(lastname)
a = datetime.date.today().year
b = datetime.date.today().month
c = datetime.date.today().day
d = datetime.datetime.now().hour
e = datetime.datetime.now().minute
# 获取时间
if b