開始
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文件轉(zhuǎn)成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)
···