[問題] 將資料夾裡的檔名篩選並寫到QTextBrowser

看板Python作者 (無奈)時間8年前 (2017/04/16 23:26), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
我原本是這樣寫的 把檔名只要有"-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
上面那部份應該先檢查thefiledate是不是被改過名字了再appe
04/18 08:19, 1F

04/18 08:19, , 2F
nd進去
04/18 08:19, 2F

04/19 07:02, , 3F
謝謝樓上
04/19 07:02, 3F

04/19 12:32, , 4F
我突然發現遇到Thumbs.db就會出現錯誤
04/19 12:32, 4F

04/19 12:33, , 5F
可能要判定檔案被開啓就跳過執行
04/19 12:33, 5F
文章代碼(AID): #1OyuqOhO (Python)
文章代碼(AID): #1OyuqOhO (Python)