Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used this code to get the directory size of 2 directories, if one directory didnt exist, it would show Zero KB. Otherwise, the second half of the code will display the folder size along with the KB, MB, GB, respectively, and it will also display it in a clean format: <code>10.02 MB</code>.</p> <p>Try this something like this: </p> <pre><code>- (unsigned long long int)folderSize:(NSString *)folderPath { NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil]; NSEnumerator *filesEnumerator = [filesArray objectEnumerator]; NSString *fileName; unsigned long long int fileSize = 0; while (fileName = [filesEnumerator nextObject]) { NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES]; fileSize += [fileDictionary fileSize]; } return fileSize; } -(NSString *)getMPSize { NSString*sizeTypeW = @"bytes"; int app = [self folderSize:@"/PathToTheFolderYouWantTheSizeOf/"]; NSFileManager *manager = [NSFileManager defaultManager]; if([manager fileExistsAtPath:@"/AnotherFolder/"] == YES){ int working = [self folderSize:@"/AnotherFolder/"]; if(working&lt;1){ return @"Size: Zero KB"; }else{ if (working &gt; 1024) { //Kilobytes working = working / 1024; sizeTypeW = @" KB"; } if (working &gt; 1024) { //Megabytes working = working / 1024; sizeTypeW = @" MB"; } if (working &gt; 1024) { //Gigabytes working = working / 1024; sizeTypeW = @" GB"; } return [NSString stringWithFormat:@"App: %i MB, Working: %i %@ ",app/1024/1024, working,sizeTypeW]; } }else{ return [NSString stringWithFormat:@"App: %i MB, Working: Zero KB",app/1024/1024]; } [manager release]; } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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