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 7414929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:11:58+00:00 2026-05-29T07:11:58+00:00

I currently have a UITableView showing my app’s document directory. How can I get

  • 0

I currently have a UITableView showing my app’s document directory. How can I get the file size of the current row’s document?

My code is currently as follows:

- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    // layout the cell
    cell.textLabel.text = [self.drive.filesArray objectAtIndex:indexPath.row];
    NSInteger iconCount = [docInteractionController.icons count];
    cell.imageView.image = [docInteractionController.icons objectAtIndex:iconCount - 1];

    NSString *fileURLString = [self.drive.filesArray objectAtIndex:indexPath.row];
    NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fileURLString error:nil];
    NSString *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
    long long fileSize = [fileSizeNumber longLongValue];

    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@",
                                 fileSizeNumber, [self.drive.filesArray objectAtIndex:indexPath.row]];

    return cell;
}

Unfortunately this doesn’t work though. Any ideas?

  • 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-29T07:11:58+00:00Added an answer on May 29, 2026 at 7:11 am

    I don’t know what self.drive.filesArray is, but if you do it with NSDocumentDirectory, get path and then files in that path, it will work.

    Here is sample which work for me and I think this is the way how to deal with document directory for application on iOS:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *files = [fm contentsOfDirectoryAtPath:documentsDirectory error:nil];
    NSString *fileFirst = [files objectAtIndex:0];
    NSString *fullPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileFirst];
    NSDictionary *attrs = [fm attributesOfItemAtPath:fullPath error:nil];
    long long fileSize = [attrs fileSize];
    
    NSLog(@"File is %@ and size is %lld",fileFirst, fileSize)
    

    You will end up with something similar like

    2012-01-28 22:34:00.916 fileOperations[57498:f803] File is smallImage.jpg and size is 30979
    

    I think you still have wrong path, mine (on iPhone with iOS 5.0.1) is

    /var/mobile/Applications/DA47CD6A-8AA8-4739-8CCB-6087F30C0954/Documents/smallImage.jpg
    

    point here is Documents. Correct your code to get right path, save files to right path and you should be able to get attributes from files. Your file probably doesn’t exist or fm just doesn’t have rights to get what you want. I don’t know, because you send errors from file manager to nil object. Also question, how are you collecting self.drive.filesArray array?
    Try to collect your self.drive.filesArray that way, I wrote above. It works.

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

Sidebar

Related Questions

I have a question - how can I get a number of row selected
Currently i have a uitableview that the user can scroll through and select a
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I have a UITableView (on a navigation controller stack) which is showing details for
I currently have a UIScrollView which has a content size equal to about 50
Short Intro Currently I have a UITableView which is filled with custom cells that
Short Explanation Currently I have a UITableView which contains cells of videos from a
I'm building an iPhone app with a UITableView. On selecting a row, I'd like
I have a UITableView, and currently it has a single cell in it. I
I have a grouped uitableview which has several sections. The sections are showing up

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.