iPhone-文件属性

iPhone-文件属性,iphone,uitableview,nsfilemanager,Iphone,Uitableview,Nsfilemanager,我正在创建一个应用程序,使iphone可以作为一个pendrive,以便于文件共享 在第一阶段,我在一个目录中有一些文件(png、pdf、jpg、zip),我让它们以可变数组的形式显示在tableview中。它显示在tableView中,如下所示 .DS_Store .localized gazelle.pdf Hamburger_sandwich.jpg IITD TAJ Picture 028_jpg.jpg iya_logo_final_b&w.jpg manifesto09-en

我正在创建一个应用程序,使iphone可以作为一个pendrive,以便于文件共享

在第一阶段,我在一个目录中有一些文件(png、pdf、jpg、zip),我让它们以可变数组的形式显示在tableview中。它显示在tableView中,如下所示

.DS_Store
.localized
gazelle.pdf
Hamburger_sandwich.jpg
IITD TAJ Picture 028_jpg.jpg
iya_logo_final_b&w.jpg
manifesto09-eng.pdf
RSSReader.sql
SimpleURLConnections.zip
SQLTutorial
我只想显示文件名,不想显示扩展名。我知道可以在NSFileManager中提取文件的扩展名。但我不知道怎么做。请帮助我使我的表视图如下所示

.DS_Store
.localized
gazelle
Hamburger_sandwich
IITD TAJ Picture 028_jpg
iya_logo_final_b&w
manifesto09-eng
RSSReader
SimpleURLConnections
SQLTutorial
在第二个阶段中,我有一个detailedViewController,它获取并显示文件的详细视图,如

  • 文件大小
  • 文件类型
  • 如果它是图像,则应在imageView中打开
  • 如果它是一首歌,它应该播放它

  • 因此,我需要检索文件路径、文件类型、文件大小等属性。。每个文件的名称。如果可能的话,请给我一个指导。我也不知道如何将可变数组转换为NSString并调用stringByDeletingPathExtension等方法。请帮帮我。如果需要,我甚至可以发送我的源代码。如果可能,请使用一些示例代码和教程指导我。

    我希望您将文件名保存在NSURL对象中,如果是这样,您可以使用以下代码仅获取文件名,并可以从字符串中删除文件扩展名

    NSArray *fileName = [[fileURL lastPathComponent] componentsSeparatedByString:@"."];
    NSLog(@"%@",[fileName objectAtIndex:0]);
    
    这应该有效:) 这将获取NSString*parentDirectory中某个目录中的所有文件,获取其大小,如果图像执行其他操作,则假定它是一个声音文件

    NSFileManager *fm = [NSFileManager defaultManager];
    NSError *error = nil;
    NSArray *filePaths = [fm contentsOfDirectoryAtPath:parentDirectory error:&error];
    if (error) {
        NSLog(@"%@", [error localizedDescription]);
        error = nil;
    }   
    for (NSString *filePath in filePaths) {
        //filename without extension
        NSString *fileWithoutExtension = [[filePath lastPathComponent] stringByDeletingPathExtension];
    
        //file size
        unsigned long long s = [[fm attributesOfItemAtPath:[parentDirectory stringByAppendingPathComponent:filePath] 
                                      error:NULL] fileSize];
    
        UIImage *image = [UIImage imageNamed:[parentDirectory stringByAppendingPathComponent:filePath];];
        //if image...
        if(image){
            //show it here
        }
        else{
            //otherwise it should be music then, play it using AVFoundation or AudioToolBox
        }
    
    }
    

    没有。我在文档目录中有这些文件。我根本没有使用url。我需要在tableView中显示目录中的内容,而不显示文件扩展名。。谢谢你的答复。。