import os s = "java" p = "d:lw" m = 1024 * 1024 * 1024 #查找文件名 def find_file(): for root, dirs, files in os.walk(p): for f in files: if f.find(s) != -1: name = os.path.abspath(os.path.join(root, f)) print(name) #查找大文件 def find_max_file(): for root, dirs, files in os.walk(p): for f in files: name = os.path.abspath(os.path.join(root,f)) if os.path.getsize(name) > m: print(name+' '+str(os.path.getsize(name)/m)+'G') #主程序 def main(): #find_file() find_max_file() if __name__ == '__main__': main()