IOS gets file attributes. (including creation date)

IOS gets file attributes. (including creation date)

 

FileInfo *fileInfo = [[FileInfo alloc] init];
        fileInfo.name = fileName;
        fileInfo.path = [rootPath stringByAppendingPathComponent:fileName];
        
        / / Determine whether it is a folder or a document
        BOOL isDir = YES;
        [fileManager fileExistsAtPath:fileInfo.path isDirectory:&isDir];
        if (isDir) {
            //folder
            fileInfo.isDir = YES;
            fileInfo.isLock = NO;
        }else{
            //document
        }
        
        NSError *error = nil;
        NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fileInfo.path error:&error];
        if (fileAttributes) {
            NSNumber *fileSize;
            NSString *fileOwner, *creationDate;
            NSDate * fileModDate;
            //File size
            if ((fileSize = [fileAttributes objectForKey:NSFileSize])) {
                NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);
                if (!fileInfo.isDir) {
                    fileInfo.size = [fileSize intValue];
                }
            }
            // file creation date
            if ((creationDate = [fileAttributes objectForKey:NSFileCreationDate])) {
                NSLog(@"File creationDate: %@\n", creationDate);
                fileInfo.date = creationDate;
            }
            // file owner
            if ((fileOwner = [fileAttributes objectForKey: NSFileOwnerAccountName])) {
                NSLog(@"Owner: %@\n", fileOwner);
            }
            // file modification date
            if ((fileModDate = [fileAttributes objectForKey: NSFileModificationDate])) {
                NSLog(@"Modification date: %@\n", fileModDate);
            }
        }

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326610809&siteId=291194637