Discuss / Python / 找文件我的怎么写的这么复杂

找文件我的怎么写的这么复杂

Topic source

花朝zhe

#1 Created at ... [Delete] [Delete and Lock User]

import os from datetime import datetime

def find_file(str,path="."): file_pwd=[] def fun(str,path="."): now_path=os.path.abspath(path) file_list=[x for x in os.listdir(now_path) if os.path.isfile(os.path.join(now_path,x))] dir_list=[x for x in os.listdir(now_path) if os.path.isdir(os.path.join(now_path,x))] for i in file_list: if str in i: file=[] file.append(os.path.getsize(os.path.join(now_path,i))) file.append(datetime.fromtimestamp(os.path.getmtime(os.path.join(now_path,i))).strftime("%Y-%m-%d %H:%M")) file.append(i) file.append(os.path.abspath(i)) file_pwd.append(file) for i in dir_list: new_path=os.path.join(now_path,i) fun(str,new_path) fun(str,path) for i in file_pwd: print(i) return file_pwd

x=find_file("test")


  • 1

Reply