讀取絕對路徑下資料夾的子目錄檔案

2021-08-21 05:38:24 字數 1186 閱讀 2198

由於實習專案的需要,最近在公司完成讀取絕對路徑下資料夾的子目錄檔案。包括子資料夾,各種文件。因為專案比較急,所以用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))

win = wx.frame(none, title="****** 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()

小白第一次發部落格,希望大家多多指教,共同進步。

獲取src下檔案的絕對路徑

前提 該檔案必須在模組 module 的src目錄下。檔案直接存在src目錄下,不在包中 string path thread.currentthread getcontextclassloader getresource 檔名 getpath system.out.println 絕對路徑 pat...

由資料夾絕對路徑獲取對應的PIDL

cstring strpath lpitemidlist lpi null ishellfolder m lpsfdesktop char path max path olechar szolestr max path getcurrentdirectory max path,path strpat...

388 檔案的最長絕對路徑

難度 中等 題目描述 思路總結 題解一用到了棧,存當前目錄的所有層級的名字,然後每次遇到檔案型別計算當前最長的路徑。具體步驟都在注釋中寫的很詳細。有時間可以做一下不用棧的方法,不過當前的核心任務還是理解並使用棧。題解一 class solution def lengthlongestpath sel...