读取绝对路径下文件夹的子目录文件

                       

             由于实习项目的需要,最近在公司完成读取绝对路径下文件夹的子目录文件。包括子文件夹,各种文档。因为项目比较急,所以用Python开发,为了方便使用,并用Wxpython做成交互界面,下面就是具体代码。

# -*- coding: utf-8 -*-
import wx
import os
def load1(event):  
  dialog1 = wx.DirDialog(None,'Notepad',style = wx.FD_OPEN)
  if dialog1.ShowModal() == wx.ID_OK: 
     dirname1.SetValue(dialog1.GetPath())
    #dir = open(dialog.GetPath())
    #dirPath = open(dirname.GetValue().strip())
     full_path = dirname1.GetValue() + '.txt'
     f = open(full_path,'w')
     print dirname1.GetValue().strip()
  for dirpath, dirnames, filenames in os.walk(dirname1.GetValue().strip()):
        print filenames
        for filename in dirnames:
             print >> f,(os.path.join(filename))
        for filename in filenames:
             print >> f,(os.path.join(filename))
         
app = wx.App()  
win = wx.Frame(None, title="Simple Editor", size=(420,100)) 

loadButton1 = wx.Button(win, label='Open',pos=(225,5),size =(80,25))  
loadButton1.Bind(wx.EVT_BUTTON, load1)
dirname1 = wx.TextCtrl(win,pos=(5,5),size =(210,25))

Label = wx.StaticText(win,-1, u"注:保存路径在E盘", pos = (15,30))


win.Show()
app.MainLoop() 

小白第一次发博客,希望大家多多指教,共同进步。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值