[問題] 將資料夾裡的檔名篩選並寫到QTextBrowser
我原本是這樣寫的
把檔名只要有"-abc"的字串改為今日日期並把帶有今日日期的檔案列出來
但發現QTextBrowser會把該資料夾裡所有檔案通通都列出來
def rename(self):
oldfile = next(os.walk(self.QLineEdit.text()))[2]
for thefileok in oldfile:
thefiledate = thefileok.replace(('-abc.'),time.strftime('_%Y%m%d.'))
os.rename(thefileok, thefiledate)
self.QTextBrowser.append(thefiledate)
後來我改下面這樣就解決了 但仍然不懂上面的方式為何無法達成
def rename(self):
oldfile = next(os.walk(self.QLineEdit.text()))[2]
for thefileok in oldfile:
thefiledate = thefileok.replace(('-abc.'),time.strftime('_%Y%m%d.'))
os.rename(thefileok, thefiledate)
thefiledatelist = glob.glob(time.strftime('*_%Y%m%d.*'))
thefiledatestr = '\n'.join(thefiledatelist)
self.QTextBrowser.append(thefiledatestr)
希望有高手可以解惑 感謝
--
下列何者最容易爆肝?
1、 固定上班時間,做三休三,需日夜輪班,可以打屁聊天,沒有加班,不會on call
2、 基本12個小時,全年無休,假日也要來,禁止打混摸魚,常常加班,隨時on call
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.161.143.180
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1492356376.A.AD8.html
→
04/18 08:19, , 1F
04/18 08:19, 1F
→
04/18 08:19, , 2F
04/18 08:19, 2F
→
04/19 07:02, , 3F
04/19 07:02, 3F
→
04/19 12:32, , 4F
04/19 12:32, 4F
→
04/19 12:33, , 5F
04/19 12:33, 5F
Python 近期熱門文章
PTT數位生活區 即時熱門文章