iOS - Get sum of filesize in directory

假装没事ソ 提交于 2019-12-03 08:40:55
Daniel

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!