python - 将多个文件名与同一目录中名称的前缀进行比较
问题描述
我在同一目录中有多个 .png 和 .json 文件。我想检查目录中可用的文件是否同名或不喜欢 a.png & a.json、b.png & b.json
解决方案
你可以试试这个:
import os
_, _ ,files = os.walk('.').next()
json = [f[:-5] for f in files if f.endswith('.json')]
png = [f[:-4] for f in files if f.endswith('.png')]
json_only = set(json) - set(png)
png_only = set(png) - set(json)
json_and_png = set(json) & set(png)
... etc...
推荐阅读
- wordpress - 设置 Wordpress 块教程的正确步骤?
- flutter - 无法在颤动中显示 RewardedVideoAd AdMob 广告
- javascript - iOS上的c ++,如何将抽象类型变量移动到线程中?
- c# - 将值从一个用户控件传递到另一个用户控件
- java - 按列表值分组并查找列表中使用的元素总数
- javascript - 节点 express 引用错误响应未定义
- c - 如何将调用函数作为 strcpy 中的第二个字符串?
- html - 忽略markdown-it中指定的HTML块?
- python - 如何通过在python代码中导入sqlite3来打开或创建数据库
- unity3d - 父对象时未调用 OnCollisionExit