zoukankan      html  css  js  c++  java
  • Python学习(一):查找大文件

    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()
  • 相关阅读:
    leetcode122
    leetcode121
    leetcode773
    leetcode803
    leetcode658
    leetcode723
    leetcode134
    leetcode340
    leetcode721
    leetcode362
  • 原文地址:https://www.cnblogs.com/liw66/p/11971901.html
Copyright © 2011-2022 走看看