Note that there are some explanatory texts on larger screens.

plurals
  1. POFileSize Problem - Cocoa
    primarykey
    data
    text
    <p>I've written methods that help me get the size of files/folders and translate the result in a human readable string. Problem is, when this size exceeds about 2.1GB, the number returned changes to a random negative number, like "-4324234423 bytes", which is useless.</p> <p>Things I've found out about &amp; done about this issue:</p> <ul> <li>32GB is limited to this size, so I compile in 64bit instead.</li> <li>I've tried using both CGFloat and NSUInteger, but both still return the same value as NSInteger.</li> </ul> <p>I am quite frustrated, I don't know what I am missing. Here are my methods:</p> <pre><code>- (NSString *)stringFromFileSize:(int)theSize { CGFloat floatSize = theSize; if (theSize&lt;1023) return([NSString stringWithFormat:@"%i bytes",theSize]); floatSize = floatSize / 1024; if (floatSize&lt;1023) return([NSString stringWithFormat:@"%1.1f KB",floatSize]); floatSize = floatSize / 1024; if (floatSize&lt;1023) return([NSString stringWithFormat:@"%1.2f MB",floatSize]); floatSize = floatSize / 1024; return([NSString stringWithFormat:@"%1.2f GB",floatSize]); } - (NSUInteger)sizeOfFile:(NSString *)path { NSDictionary *fattrib = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil]; NSUInteger fileSize = (NSUInteger)[fattrib fileSize]; return fileSize; } - (NSUInteger)sizeOfFolder:(NSString*)folderPath { NSArray *contents; NSEnumerator *enumerator; NSString *path; contents = [[NSFileManager defaultManager] subpathsAtPath:folderPath]; enumerator = [contents objectEnumerator]; NSUInteger fileSizeInt = 0; while (path = [enumerator nextObject]) { NSDictionary *fattrib = [[NSFileManager defaultManager] attributesOfItemAtPath:[folderPath stringByAppendingPathComponent:path] error:nil]; fileSizeInt +=[fattrib fileSize]; } return fileSizeInt; } </code></pre> <p>What am I missing? Is NSFileManager returning a 32bit value? What's causing this?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload