Search code examples
macoscocoafilefilesystemsmacos-carbon

OSX : get size on disk for a file/directory


I am looking for a way (the fastest, working for both files and directory and accurate) to get the size of disk (not the file size) of a file or directory, using either: - BSD functions - Carbon functions - Cocoa functions

Thanks !


Solution

  • If you have a file URL, you can use -[NSURL resourceValuesForKeys:error:] to get these values:

    • NSURLFileSizeKey; <-- file size in bytes
    • NSURLFileAllocatedSizeKey; <-- file size on disk