作者tom600488 (无奈)
看板Python
标题[问题] 将资料夹里的档名筛选并写到QTextBrowser
时间Sun Apr 16 23:26:13 2017
我原本是这样写的
把档名只要有"-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://webptt.com/cn.aspx?n=bbs/Python/M.1492356376.A.AD8.html
1F:→ qee93: 上面那部份应该先检查thefiledate是不是被改过名字了再appe 04/18 08:19
2F:→ qee93: nd进去 04/18 08:19
3F:→ tom600488: 谢谢楼上 04/19 07:02
4F:→ tom600488: 我突然发现遇到Thumbs.db就会出现错误 04/19 12:32
5F:→ tom600488: 可能要判定档案被开啓就跳过执行 04/19 12:33