I have a folder that contains 4 text files. I want to program a code with which I would be able to check the size of the files in my folder and only open those that has equal sizes. Anyone has any idea?
I have already tried this
import os
d=os.stat('H:/My Documents/211').st_size
I can't reproduce your error. This
import os
print os.path.getsize('mydata.csv')
print os.stat('mydata.csv').st_size
Yields
359415
359415
I'm guessing that the filename you provide is wrong. This will print the size of all files in a folder
my_dir = r'path/to/subdir/'
for f in os.listdir(my_dir):
path = os.path.join(my_dir, f)
if os.path.isfile(path):
print os.path.getsize(path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With