python随机搜索并打开该路径内的文件,,标签:
标签: <python随机搜索并打开该路径内的文件>

1.[python随机搜索并打开该路径内的文件代码][Python]代码

# -*- coding: utf8 -*-import osimport random#所有视频路径basepath="F:"#存储取到的视频列表C=[]def listmovie(a):    #获取路径下的所有文件    b=os.listdir(a)    for i in range(0,len(b)):        c=a+"/"+b[i]        if(os.path.isdir(c) and i!=3):            listmovie(c)        else:            if(b[i][-3:]=="mkv"):                C.append(a+"/"+b[i])listmovie(basepath)Q=C[random.randint(0,len(C))]#用默认程序打开指定文件os.startfile(Q)

编橙之家文章,

评论关闭