0

I am trying to create a program which auto-backups some folders under certain circumstances. I try to compare the size of two folders (source and dest), source has files in it, a flac file and a subfolder with a text file whereas dest is empty.

This is the code I've written so far:

import os.path
sls = os.path.getsize('D:/autobu/source/')
dls = os.path.getsize('D:/autobu/dest/')
print(sls)
print(dls)
if sls > dls:
    print('success')
else:
    print('fail')

And the output is this:

0
0
fail

What have I done wrong? Have I misunderstood how getsize functions?

AQUATH
  • 33
  • 2
  • 12
  • Possible duplicate of [Calculating a directory size using Python?](http://stackoverflow.com/questions/1392413/calculating-a-directory-size-using-python) – Łukasz Rogalski Jul 28 '16 at 12:39

1 Answers1

0

os.path.getsize('D:/autobu/source/') is used for getting size of a file you can folder size you can use os.stat

src_stat = os.stat('D:/autobu/source/')
sls = src_stat.st_size
  • Doesn't seem to work either. Yours as mine, only calculate a single file. For a whole folder I should probably use the code in Lukasz's link. – AQUATH Jul 28 '16 at 14:44