TXT文件按條件批量刪除行工具 v2.9

2024-04-01發(fā)布者:zhangliang大?。?/span> 下載:0

文件大小:

軟件介紹

TXT文件按條件批量刪除行工具是用Python語言寫的一款文本處理軟件,源碼開放,界面簡(jiǎn)單易用,支持批量刪除行含關(guān)鍵字或詞的行、空行以及批量字符小于多少刪除行,使用的時(shí)候只需要操作幾個(gè)步驟即可進(jìn)行轉(zhuǎn)換,非常方便,效率高,減少不必要的時(shí)間浪費(fèi),歡迎下載使用。

軟件特色

批量刪除行含關(guān)鍵字或詞的行(多個(gè)關(guān)鍵字/詞中間用空格隔開)

批量刪除空行

批量字符小于多少(可設(shè)定)刪除行

使用方法

點(diǎn)擊打開文件批量選擇TXT文件。

需要的功能前打勾,并配置。

點(diǎn)擊【開始 】即可進(jìn)行轉(zhuǎn)換。

最后會(huì)生成原文件名+_new.txt的文件。

源碼一覽

import os

import tkinter

from tkinter import ttk, filedialog, messagebox # 有Combobox、LabelFrame 組件時(shí)需要本語句

FilePaths = ()

def getTxtFiles():

global FilePaths

files = filedialog.askopenfilenames(filetypes=[('text files', '.txt')])

if files:

FilePaths = files

# print(FilePaths)

for f_name in files:

ctrl_FileListBox.insert('end', f_name)

ctrl_FileListBox.insert(tkinter.INSERT, ' ')

else:

messagebox.showinfo(title='提示', message='沒有選擇任何文件!')

def KeyWordScan(keys, s):

key_words = keys.split(" ")

t_f = False

for key_word in key_words:

if key_word in s:

t_f = True

return t_f

def ctrl_StartBtn_clicked():

has_key_words = int_CheckBox1.get()

key_words = str_KeyWord.get()

has_empty_line = int_CheckBox2.get()

has_N = int_CheckBox3.get()

n = str_KeyNum.get()

for file in FilePaths: # 循環(huán)遍歷文件

s_file = open(os.path.splitext(file)[0]+"_new"+os.path.splitext(file)[1], 'w+') # 文件保存位置

f_lines = open(file, encoding='utf8').readlines() # 打開文件,讀入每一行

for s in f_lines: # s: 每一行的內(nèi)容

# 操作1

if has_key_words:

if KeyWordScan(key_words, s):

continue

# 操作2

if has_empty_line:

if len(s.strip()) == 0:

continue

# 操作3:

if has_N:

if len(s.strip()) < int(n):

continue

s_file.write(s)

s_file.close() # 關(guān)閉文件

root = tkinter.Tk() # 設(shè)定窗體變量

root.geometry('450x300') # 格式('寬x高+x+y')其中x、y為位置

root.title('TxT文件處理助手V0.1 By 52poje Loker')

ctrl_Frame1 = ttk.LabelFrame(root, text='選項(xiàng)')

ctrl_Frame1.place(x=14, y=72, width=388, height=101)

ctrl_StartBtn = tkinter.Button(root, text='確定', font=('宋體', '9'),

command=ctrl_StartBtn_clicked) # 可在括號(hào)內(nèi)加上調(diào)用函數(shù)部分 ,command=ctrl_StartBtn_clicked

ctrl_StartBtn.place(x=22, y=223, width=72, height=29)

ctrl_QuitBtn = tkinter.Button(root, text='取消', font=('宋體', '9')) # 可在括號(hào)內(nèi)加上調(diào)用函數(shù)部分 ,command=ctrl_QuitBtn_clicked

ctrl_QuitBtn.place(x=108, y=223, width=72, height=29)

ctrl_FileListBox = tkinter.Text(root, font=('宋體', '9'))

ctrl_FileListBox.place(x=14, y=7, width=260, height=38)

ctrl_Scrollbar1 = tkinter.Scrollbar(root, command=ctrl_FileListBox.xview, orient=tkinter.HORIZONTAL)

ctrl_Scrollbar1.place(x=14, y=46, width=261, height=16)

ctrl_Scrollbar2 = tkinter.Scrollbar(root, command=ctrl_FileListBox.yview, orient=tkinter.VERTICAL)

ctrl_Scrollbar2.place(x=275, y=7, width=16, height=39)

ctrl_FileListBox.config(xscrollcommand=ctrl_Scrollbar1.set, yscrollcommand=ctrl_Scrollbar2.set, wrap='none')

int_CheckBox1 = tkinter.IntVar() # 綁定變量

ctrl_CheckBox1 = tkinter.Checkbutton(ctrl_Frame1, text='刪除行含關(guān)鍵字或詞的行', variable=int_CheckBox1, font=('宋體', '9'))

ctrl_CheckBox1.place(x=14, y=14, height=22) # 考慮到對(duì)齊問題,不列入寬度,需要時(shí)手動(dòng)加入 width=130

ctrl_CheckBox1.deselect() # 默認(rèn)為未選中狀態(tài)

Ctrl_Label1 = tkinter.Label(ctrl_Frame1, text="關(guān)鍵字:")

Ctrl_Label1.place(x=180, y=14, width=55, height=22)

str_KeyWord = tkinter.StringVar() # 綁定變量

ctrl_KeyWord = tkinter.Entry(ctrl_Frame1, textvariable=str_KeyWord, font=('宋體', '9'))

ctrl_KeyWord.place(x=230, y=14, width=150, height=22)

int_CheckBox2 = tkinter.IntVar() # 綁定變量

ctrl_CheckBox2 = tkinter.Checkbutton(ctrl_Frame1, text='刪除空行', variable=int_CheckBox2, font=('宋體', '9'))

ctrl_CheckBox2.place(x=14, y=36, height=22) # 考慮到對(duì)齊問題,不列入寬度,需要時(shí)手動(dòng)加入 width=130

ctrl_CheckBox2.deselect() # 默認(rèn)為未選中狀態(tài)

int_CheckBox3 = tkinter.IntVar() # 綁定變量

ctrl_CheckBox3 = tkinter.Checkbutton(ctrl_Frame1, text='刪除字符小于N的行', variable=int_CheckBox3, font=('宋體', '9'))

ctrl_CheckBox3.place(x=14, y=58, height=22) # 考慮到對(duì)齊問題,不列入寬度,需要時(shí)手動(dòng)加入 width=130

ctrl_CheckBox3.deselect() # 默認(rèn)為未選中狀態(tài)

Ctrl_Label = tkinter.Label(ctrl_Frame1, text="N =")

Ctrl_Label.place(x=220, y=58, width=22, height=22)

str_KeyNum = tkinter.StringVar() # 綁定變量

ctrl_KeyNum = tkinter.Entry(ctrl_Frame1, textvariable=str_KeyNum, font=('宋體', '9'))

ctrl_KeyNum.place(x=250, y=58, width=22, height=22)

ctrl_OpenFileBtn = tkinter.Button(root, text='選擇文件',

font=('宋體', '9'),

command=getTxtFiles) # 可在括號(hào)內(nèi)加上調(diào)用函數(shù)部分 ,command=ctrl_OpenFileBtn_clicked

ctrl_OpenFileBtn.place(x=305, y=18, width=72, height=29)

# str_OutputPath = tkinter.StringVar() # 綁定變量

# ctrl_OutputPath = tkinter.Entry(root, textvariable=str_OutputPath, font=('宋體', '9'))

# ctrl_OutputPath.place(x=14, y=187, width=209, height=22)

root.mainloop()

軟件測(cè)評(píng)

按照用戶需求進(jìn)行TXT文件處理

能實(shí)現(xiàn)指定行批量刪除功能

提高了工作效率

image.png

發(fā)表評(píng)論(共0條評(píng)論)
請(qǐng)自覺遵守互聯(lián)網(wǎng)相關(guān)政策法規(guī),評(píng)論內(nèi)容只代表網(wǎng)友觀點(diǎn),發(fā)表審核后顯示!

版權(quán)聲明:

1 本站所有資源(含游戲)均是軟件作者、開發(fā)商投稿,任何涉及商業(yè)盈利目的均不得使用,否則產(chǎn)生的一切后果將由您自己承擔(dān)!

2 本站將不對(duì)任何資源負(fù)法律責(zé)任,所有資源請(qǐng)?jiān)谙螺d后24小時(shí)內(nèi)刪除。

3 若有關(guān)在線投稿、無法下載等問題,請(qǐng)與本站客服人員聯(lián)系。

4 如侵犯了您的版權(quán)、商標(biāo)等,請(qǐng)立刻聯(lián)系我們并具體說明情況后,本站將盡快處理刪除,聯(lián)系QQ:2499894784

返回頂部