Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 625517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:19:05+00:00 2026-05-13T19:19:05+00:00

how do i get size of folder NSCachesDirectory i.e /Library/Cache. i want to know

  • 0

how do i get size of folder NSCachesDirectory i.e /Library/Cache. i want to know size of this folder so that i can eventually clear this.

thanks.

Edit: here is my code.

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:folderPath error:&error];
if (attributes != nil) {

    if (fileSize = [attributes objectForKey:NSFileSize]) {
        NSLog(@"size of :%@ = %qi\n",folderPath, [fileSize unsignedLongLongValue]);
    }

}

when i run this it gives my file size 768(dont know bytes or KB) and i check in finder it shows me folder size 168KB. i dont know whats wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:19:06+00:00Added an answer on May 13, 2026 at 7:19 pm

    Something like the following should help get you started:

    - (unsigned long long int) cacheFolderSize {
        NSFileManager *_manager = [NSFileManager defaultManager];
        NSArray *_cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *_cacheDirectory = [_cachePaths objectAtIndex:0]; 
        NSArray *_cacheFileList;
        NSEnumerator *_cacheEnumerator;
        NSString *_cacheFilePath;
        unsigned long long int _cacheFolderSize = 0;
    
        _cacheFileList = [_manager subpathsAtPath:_cacheDirectory];
        _cacheEnumerator = [_cacheFileList objectEnumerator];
        while (_cacheFilePath = [_cacheEnumerator nextObject]) {
            NSDictionary *_cacheFileAttributes = [_manager fileAttributesAtPath:[_cacheDirectory stringByAppendingPathComponent:_cacheFilePath] traverseLink:YES];
            _cacheFolderSize += [_cacheFileAttributes fileSize];
        }
    
        return _cacheFolderSize;
    }
    

    EDIT

    The value returned will be in bytes: cf. http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSFileSize

    Assuming you are running this in the Simulator, Finder is probably reporting usage of file blocks for those bytes. Those blocks will necessarily be larger than the file data itself. Read up on the HFS+ system to learn about blocks: http://en.wikipedia.org/wiki/HFS_Plus

    I’m not sure what file system is used on the iPhone, or what the file block size will be on the device, so while the byte total will be the same, the actual disk usage may be different between Simulator and device.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create functions what get the folder size. I write small function:
For example. I have folder MyFolder And I want to get the size of
Right now I'm using this code to get the size of a folder: NSArray
I've already build a recursive function to get the directory size of a folder
In mssql2005 when I want to get size of table in MBs, I use
How can I get the size in bytes of the data returned from the
How can i get the size of an Document object? DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
How to get folder size in Adobe Air?
Possible Duplicate: Size of folder or file I used this code to instantiate a
I want to write a script that will: 1- locate folder store on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.