遍历文件夹下所有文件名,并存放在txt中,分带后缀名与不带后缀名的(tkinter库)

#coding:utf-8
from tkinter import *
import os
def fc():
    if input.get() == "":
        txt.insert(END,"请输入有效数据"+"\n")

    else:
        path_list = os.listdir(input.get())#获取gui上输入的值
        for picture_name in path_list:
            with open("Remove_suffix.txt", "a") as f:
                f.write(picture_name.split(".")[0] + "\n")
                print("去掉后缀名:", picture_name.split(".")[0])
                txt.insert(END, picture_name.split(".")[0]+"\n")
                input.delete(0, END)
            with open("Suffix_exists.txt", "a") as f:
                f.write(picture_name + "\n")
                print("存在后缀名:", picture_name.split()[0])
                txt.insert(END, picture_name.split()[0]+"\n")
windos = Tk()
windos.geometry("460x240")#设置gui窗口大小
windos.title("获取文件夹下所有文件名")#gui窗口title名
la = Label(windos,text="请输入文件夹名称")#gui页面title名称
la.place(relx=0.1,rely=0.1,relwidth=0.8,relheight=0.1)
input = Entry(windos)#输入框设置
input.place(relx=0.35,rely=0.2,relwidth=0.3,relheight=0.1)
button = Button(windos,text="确定",command=fc)#按钮设置名字,按钮执行方法
button.place(relx=0.55,rely=0.2,relwidth=0.1,relheight=0.1)
txt = Text(windos)#gui输出页面
txt.place(relx=0.25,rely=0.3,relwidth=0.5,relheight=0.5)
windos.mainloop()#启动
#if __name__ == '__main__':
#    fc()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

stepan.jiang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值