im a newbie to python still so bare with me if i have gone down the wrong route or my explanation is confusing!!
any ideas on how i can sort my list by the size of the file
at the moment it is getting the size of the file and joining it with the name in to a string.
my problem - i can sort either the name or the size before i add them to the string but once they are sorted i can't work out how to match the file to the size
import os
folder = ('.')
filename=list()
f_size=list()
fsize=list()
for (path, dirs, files) in os.walk(folder):
for dirs in path:
for file in files:
filename.append(os.path.join(path, file))
for I in filename:
filesize=str(os.path.getsize(I))
f_size.append(os.path.join('['+I+' size = '+filesize+']'))
f_size.sort()
break
print (f_size)
my list looks like this so far
please don't be fooled in to thinking its already in order because i just happened to pull 4 of the list items which were in order
'[(.\\) of test1.txt) size = 63]',
'[(.\\5) of test1.txt) size = 63]',
'[(.\\6) of test1.txt) size = 63]',
'[(.\\Copy of test2.txt) size = 65]'
any help on where i am going wrong or what i can do to solve this problem would be greatly appreciated.
thanks for you time guys and girls