python - 如果在循环文件列表时文件名与 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
解决方案
推荐阅读
- javascript - Javascript - 替换字符串子字符串中的字符
- angular - 根据 ID 显示对象属性
- python - pyAV 的 pip 安装失败,退出状态为 1181
- docker - 使用 docker-compose 在 Gitlab CI 中保持 docker 构建
- javascript - 无法打开 Bootstrap 汉堡包下拉菜单或其他
- 带下拉菜单
- react-native - 按下后退按钮时反应本机贝宝包装崩溃
- azure-web-app-service - FTP 访问临时文件夹
- verilog - 我正在编写一些 verilog 代码,并且不断收到错误代码“无法解析多个常量驱动程序”?
- excel - 将 Objectname 中的变量用于 WITH 语句
- ms-access - 使 Table ms 访问 VBA