python Example Code for Searching Large Files
- 2021-07-10 20:23:37
- OfStack
As shown below:
import os,os.path
def getBigFile(pathname,filesize):# No. 1 1 The parameter is the folder to traverse, and the 2 Is the minimum file size to find
fileList = []
for root,dirs,files in os.walk(pathname):# Here os.walk() Traverse the directory
for file in files:
fname = os.path.abspath(os.path.join(root,file))
if os.path.getsize(fname)>filesize:
fileList.append(fname)# Add to the list of files found
return fileList
def main():
getBigFile("G:",300*1024*1024)# Looking for G All disks are greater than 300MB File of
if __name__=="__main__":
main()