看板 Python 關於我們 聯絡資訊
我原本是這樣寫的 把檔名只要有"-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
qee93: 上面那部份應該先檢查thefiledate是不是被改過名字了再appe 04/18 08:19
qee93: nd進去 04/18 08:19
tom600488: 謝謝樓上 04/19 07:02
tom600488: 我突然發現遇到Thumbs.db就會出現錯誤 04/19 12:32
tom600488: 可能要判定檔案被開啓就跳過執行 04/19 12:33