开始
Excel可以读取csv文件,所以我们把文件换成csv文件就可以方便的换成Excel了,而且如果知道操作Excel那就更好了,但是没找到py操作Excle的东西
直接贴代码
···
!D:\My Python\Trans_to_txt.py
注意Windows下路径表示
'''
we store the filename to the newfilename.txt
'''
import os
import docx
print('Enter your Director's path:')
mypath='F:\vscode\.vscode\python\python课\文件操作\英文分词\data\真题'
all_FileNum = 0
def Translate(level, path):
global all_FileNum
'''
将一个目录下所有doc文件转成txt
'''
ff = open("F:\vscode\.vscode\python\python课\文件操作\英文分词\data\newfilename.txt",'a+')
#该目录下所有文件的名字
files = os.listdir(path)# get the file name in the doc......
for f in files:
if '真' in f:
print(f)
ff.writelines(f+'\n')
# finalpath = path+'\'+f
#storepath = finalpath.replace(".docx",".txt")
# os.mknod(storepath)
# ss = open(storepath,"a+")
# context = docx.Document(finalpath)
# for par in context.paragraphs:
# ss.writelines(par.text)
# # #print(par.text)
# # print(" ")
else:
continue
if name == 'main':
Translate(1, mypath)
···