How to get the size of a file?

User 1 at 2.3
Sat Oct 16 23:13:46 EDT 2004


Anyone have ideas which os command could be used to get the size of a
file without actually opening it?  My intention is to write a script
that identifies duplicate files with different names.  I have no
trouble getting the names of all the files in the directory using the
os.listdir() command, but that doesn't return the file size.  In order
to be identical, files must be the same size, so I want to use file
size as the first criteria, then, if they are the same size, actually
open them up and compare the contents.  

I have written such a script in the past, but had to resort to
something like:

os.system('dir *.* >> trash.txt')

The next step was then to open up 'trash.txt', and piece together the
information I need compare file sizes.  The problems with this
approach are that it is very platform dependent (worked on WIN 95, but
don't know what else it will work on) and 8.3 filename limitations
that apply within this environment.  That is the reason I'm looking
for some other command to obtain file size before the files are ever
opened.



More information about the Python-list mailing list