im wanting to sort files by size and pick the top 20
i have managed this with the glob.glob statement but it does not work quickly and does not pick up if a file is modified/ added while the code is running.
i have worked out how to do this with OS.walk

BUT I CANNOT GET IT TO FIND THE FILE SIZE
\/\/ my code to get size of files?

import os
folder = os.walk('.')
mylist=[]

for files in folder:
  size = os.path.getsize(files)
  print (str(size))

my error message
\/\/

Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\My Documents\pyfiles\test111.py", line 6, in <module>
    size = os.path.getsize(files)
  File "C:\Python31\lib\genericpath.py", line 49, in getsize
    return os.stat(filename).st_size
TypeError: Can't convert 'tuple' object to str implicitly

any help with that would be great as cant seem to find much on getting size of a file on google.
thanks

READ THE DOC!
os.walk returns a sequence of triples (dirpath, dirnames, filenames)

suggestion: install pydoc. You only need to type pydoc os.walk in a terminal (cmd shell for windows) to see the doc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.