I'm trying to get the size on disk of a file in iOS using Objective C. As of now I've been able to get the actual size of the file and other file information using
NSFileManager
and then getting the attributes attributesOfItemAtPath:error
but not the size on disk. I also tried getting the file size from struct stat
but again it doesn't give me size on disk.I tried using NSTask
to make a call to du -h
but iOS didn't allow me to fork other processes. Any ideas are welcome :)
I know this questions is similar to many others but the difference is that I'm trying to do this in iOS and most of the methods used in other systems don't work here.
Thanks
EDIT: It's worth reading Nikolai Ruhe's answer to the same question here: https://stackoverflow.com/a/28660040/97337.
See What is the block size of the iphone filesystem? for information on the iOS block size. The size of a file on disk will be it's stat
size rounded up to the next block.