开发者

iPhone - properties of a file [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

iPhone - file properties

Hi all. i m creating an application which makes the iphone work as a pendrive for easy file sharing purpose.

In the first stage, i have some files(png, pdf, jpg, zip) in a directory and i made them display in the tableview in the form of mutable array without the extensions of each file.

In the second stage i have a detailedViewController which then displays the detailed view of the files like

  1. file size
  2. file type
  3. if it is a image, it should open in imageView
  4. if it is a song, it should play it

So i need to retrieve the properties like filePath, fileType, fileSize.. of each files. Now i got stuck in getting those properties l开发者_如何学Cike fileSize and fileType... Please help me proceed with a sample source code.

Here is my code.

- (void)listFiles {

NSFileManager *fm =[NSFileManager defaultManager];
NSError *error = nil;
NSString *parentDirectory = @"/Users/akilan/Documents";
NSArray *paths = [fm contentsOfDirectoryAtPath:parentDirectory error:&error];
if (error) {
    NSLog(@"%@", [error localizedDescription]);
    error = nil;
}
directoryContent = [[NSMutableArray alloc] init];
for (NSString *path in paths){
    documentsDirectory = [[path lastPathComponent] stringByDeletingPathExtension];
    NSLog(@"%@", documentsDirectory);
    [directoryContent addObject:documentsDirectory];

}

Thanks in advance..


you should use the method attributesOfItemAtPath:error: of your filemanager instance.
Have a look at the documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜