python 查找文件夹下视频文件

在这里插入图片描述


```python
import os
f = open(os.curdir+os.sep+'vedioList.txt','w')#创建文件
def file_move(path,target):#复杂的参数数据可以通过参数传递
    os.chdir(path)
    all_file = os.listdir(os.curdir)
    for each in all_file:
        extension = os.path.splitext(each)[1]
        if extension in target:
            f.write(os.getcwd()+os.sep+each+os.linesep)#返回对应的文件
        else:
            pass  #pass 不做任何事情,一般用做占位语句。
        if os.path.isdir(each):
            file_move(each,target)
            os.chdir(os.pardir)
        

path = input('请输入路径:')
target=['.mp4','.avi','.rmvb','.mkv']
file_move(path,target)
f.close()

发布了34 篇原创文章 · 获赞 4 · 访问量 3036

猜你喜欢

转载自blog.csdn.net/qq_41558173/article/details/103632579