iOS - Get sum of filesize in directory

前端 未结 1 2017
无人共我
无人共我 2021-02-09 19:14

I have the following code I use to cache photos I load off Flickr in the device\'s memory:

NSURL *urlForPhoto = [FlickrFetcher urlForPhoto:self.photo format:Flic         


        
1条回答
  •  孤街浪徒
    2021-02-09 19:19

    You can get the size of a file like so

    NSError *attributesError = nil;
    
        NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError];
    
        int fileSize = [fileAttributes fileSize];
    

    So you can maybe iterate through all the files in the folder and add up the file sizes...not sure if theres a direct way to get the directory size, also theres this SO post talking about this aswell, you can find a solution here

    To find the creation date of the file you can do

    NSString *path = @"";
        NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
        NSDate *result = [fileAttribs valueForKey:NSFileCreationDate]; //or NSFileModificationDate
    

    Hope it helps

    0 讨论(0)
提交回复
热议问题