如果我在遍历文件列表时文件名与python中特定的“%y%m%d”格式不匹配,如何继续下一次迭代?

问题描述

我有一些文件,这些文件名称应为'%y%m%d'格式(不必担心文件扩展名,可以是任何东西)。我正在遍历文件列表。这种'%y%m%d'格式以外的任何其他格式都应忽略,并且循环应继续下一个文件

ssh_response = VersaSsh(fqdn(host),user=user,password=pwd,sudo_password=sudo).run_command(**cmds**)

regex = "-rw-r--r-- 1 root root\s+(\d+)\s+([\w\s\d:]+)\s([\dT]+)"
match = re.finditer(regex,ssh_response,re.MULTILINE)
date_list  =[]
if match is not None:
    for matches in match :
          print(matches['somedate']) \\ **this will display the filename.ignore extension**
          date_format=datetime.datetime.strptime(matches['somedate'],'%Y%m%d')
          date = date_format.strftime('%Y-%m-%d')
          date_list.append(date)```

output : 

20200727.0.tar.gz
20200728.0.tar.gz
20200729.0.tar.gz
d2d-vnf5.txt.0.tar.gz // **loop is getting stopped at this point. Instead it should continue with the 
                       next iteration**
d2d-vnf4.txt.0.tar.gz 
20200730.0.tar.gz
20200731.0.tar.gz

 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)