python - 如何在目录下按照一定顺序提取出指定的文件名?
伊谢尔伦
伊谢尔伦 2017-04-18 10:28:09
0
1
1958
dio.log
dio.log.1
dio.log.2
dio.log.3
dio.log.4
dio.log.5
GTKBrowserLog_sleboot.log
GTKBrowserLog_sleoper.log
GTKBrowserLog_tvmticket.log
HoterStatus.log
logfiledir.txt
mode.log
mode.log.1
mode.log.2
mode.log.3
mode.log.4
mode.log.5
ParamDownload.log
sleboot.log
slebooten.log
slecomm.log
slecomm.log.1
slecommpack.log
slecommpack.log.1
slecommstatus.log
sleopercn.log
sleOperMain.log
TpuUnit1.log
TpuUnit1.log.1
TpuUnit2.log
tvmbill.log
tvmbill.log.1
tvmbill.log.2
tvmbill.log.3
tvmbill.log.4
tvmbill.log.5
tvmbillBiz.log
tvmbillBiz.log.1
tvmbillBiz.log.2
tvmbillchger.log
tvmbillchger.log.1
tvmbillchger.log.2
tvmbillchger.log.3
tvmbillchgerBiz.log
tvmcoin.log
tvmcoin.log.1
tvmcoin.log.2
tvmcoin.log.3
tvmcoin.log.4
tvmcoin.log.5
tvmcoinen.log
tvmcore.log
tvmcore.log.1
tvmcore.log.2
tvmissue.log
tvmissue.log.1
tvmissueen.log
TvmLed.log
tvmticket.log
tvmticket.log.1
tvmticket.log.2

以上是一个目录下的文件名,如何能将tvmticket.log、tvmticket.log.1、tvmticket.log.2 这3个文件的文件名提取出来存放在列表中,并且存放的顺序是['tvmticket.log.2','tvmticket.log.1','tvmticket.log']
请教各位大神如何能实现呢?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
PHPzhong

Are the names of the files you need to filter fixed? If it is fixed, separate the file name and extension, and then match it

file_lst = []
for path, dir, files in os.walk('./'):
    file_lst += files
file_count = len(file_lst) * 1.0
for key, lst in groupby(file_lst, key=lambda x: os.path.splitext(x)[0]):
    if cmp(key, 'tvmticket') == 0:
      pass
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template