zoukankan      html  css  js  c++  java
  • 查找目录下的文件


    1
    import os 2 def check_file(start_dir, target): 3 os.chdir(start_dir) 4 for each_file in os.listdir(os.curdir): 5 if each_file == target: 6 print(os.path.join(os.getcwd(), each_file)) 7 if os.path.isdir(each_file): 8 check_file(each_file,target) 9 os.chdir(os.pardir) 10 11 12 start_dir = input('请输入待查找的初始目录:') 13 target = input('请输入要查找的目标文件:') 14 check_file(start_dir, target)
     1 #查找目录下的格式文件mp4,rmvb,avi
     2 import os
     3 
     4 def check_file(start_dir):
     5     
     6     os.chdir(start_dir)
     7     for each_file in os.listdir(os.curdir):
     8         if os.path.isfile(each_file):
     9             f_extension= os.path.splitext(each_file)[1]         
    10             if f_extension in extension:
    11                 vedioList.append(os.getcwd()+each_file+os.linesep)             
    12         if os.path.isdir(each_file):
    13             check_file(each_file)
    14             os.chdir(os.pardir)      
    15                  
    16 start_dir = input('请输入待查找的初始目录:')
    17 vedioList = []
    18 extension = ['.mp4','.rmvb','.avi']
    19 check_file(start_dir)
    20 
    21 f = open('F:\veidoList.txt','a')
    22 f.writelines(vedioList)
    23 f.close()
  • 相关阅读:
    8.2
    Telnet远程控制协议
    2020/6/29
    HCIA VRP基础命令(二)
    HCIA VRP基础命令(一)
    解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'报错问题
    nginx配置文件nginx.conf
    nginx服务器搭建
    FTP服务器
    NFS
  • 原文地址:https://www.cnblogs.com/themost/p/6391659.html
Copyright © 2011-2022 走看看