首页 > IT职业 > IT职场 > python怎么判断文档是否有指定后缀?

python判断文档是否有指定后缀的方法:
import os Your_Dir='你的文件夹/' Files=os.listdir(Your_Dir) for k in range(len(Files)): # 提取文件夹内所有文件的后缀 Files[k]=os.path.splitext(Files[k])[1] Str2=['.wav','.mp3','.mp4'] if len(list(set(Str2).intersection(set(Files))))==len(Str2): return True else: return False
os.path.splitext(path):分割路径,返回路径名和文件扩展名的元组。
更多Python知识请关注Python自学网
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1386/viewspace-2833448/ ,如需转载,请注明出处,否则将追究法律责任。