Ios NSFileManager如何返回文件路径的文件夹名
我有这样一条路:Ios NSFileManager如何返回文件路径的文件夹名,ios,nsstring,nsfilemanager,Ios,Nsstring,Nsfilemanager,我有这样一条路: /Users/mac/Library/Application Support/iPhone Simulator/7.0.3/Applications/5C6B84DE-2F18-48A8-AC4D-5C4973F19050/tmp/Root/Folder 1/test.pdf 我想从这个路径中提取/Users/mac/Library/Application Support/iPhone Simulator/7.0.3/Applications/5C6B84DE-2F18-48
/Users/mac/Library/Application Support/iPhone Simulator/7.0.3/Applications/5C6B84DE-2F18-48A8-AC4D-5C4973F19050/tmp/Root/Folder 1/test.pdf
我想从这个路径中提取/Users/mac/Library/Application Support/iPhone Simulator/7.0.3/Applications/5C6B84DE-2F18-48A8-AC4D-5C4973F19050/tmp/Root/Folder 1/
我可以使用
NSFileManager
获取包含test.pdf文件的目录路径,还是需要自己解析它。您可以使用stringByDeletingLastPathComponent
NSString *path=@"";
NSString *path1= [path stringByDeletingLastPathComponent];
如果您想要不带文件名的文件路径,请使用如下命令
NSString * filePath = [path stringByDeletingLastPathComponent];
您可以使用类的
stringByDeletingLastPathComponent
执行此操作:
:
stringByDeletingLastPathComponent
返回通过从中删除最后一个路径组件而生成的新字符串
接收器,以及任何最终路径分隔符
-(NSString*)stringByDeletingLastPathComponent
NSString *path=@"";
NSString *path1= [path stringByDeletingLastPathComponent];
返回值
通过从中删除最后一个路径组件生成的新字符串
接收器,以及任何最终路径分隔符。如果接收器
表示未更改返回的根路径。讨论
请注意,此方法仅适用于文件路径(例如,
URL的字符串表示形式)
使用NSString的类方法
stringByDeletingLastPathComponent
删除最后一个路径组件。希望它能帮助你
NSString *path = @"/Users/mac/Library/Application Support/iPhone Simulator/7.0.3/Applications/5C6B84DE-2F18-48A8-AC4D-5C4973F19050/tmp/Root/Folder 1/test.pdf";
path = [path stringByDeletingLastPathComponent];
NSLog(@"path %@",path);