![图片[1]-python怎么判断文档是否有指定后缀?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ecf1a15ad9ce724.jpg)
python判断文档是否有指定后缀的方法:
importos Your_Dir='你的文件夹/' Files=os.listdir(Your_Dir) forkinrange(len(Files)): #提取文件夹内所有文件的后缀 Files[k]=os.path.splitext(Files[k])[1] Str2=['.wav','.mp3','.mp4'] iflen(list(set(Str2).intersection(set(Files))))==len(Str2): returnTrue else: returnFalse
os.path.splitext(path):分割路径,返回路径名和文件扩展名的元组。
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容