gpt4 book ai didi

ios - NSFileManager 如何返回文件路径的文件夹名称

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:07 26 4
gpt4 key购买 nike

我有这条路:

/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 文件的目录路径,还是我需要自己解析它。

最佳答案

您可以使用 NSStringstringByDeletingLastPathComponent 来完成此操作类:

NSString *path = @"/Users/mac/Library/Application Support/iPhone Simulator/7.0.3/Applications/5C6B84DE-2F18-48A8-AC4D-5C4973F19050/tmp/Root/Folder 1/test.pdf";

NSString *folder = [path stringByDeletingLastPathComponent];

Reference :

stringByDeletingLastPathComponent

Returns a new string made by deleting the last path component from the receiver, along with any final path separator.

- (NSString *)stringByDeletingLastPathComponent

Return Value

A new string made by deleting the last path component from the receiver, along with any final path separator. If the receiver represents the root path it is returned unaltered. Discussion

Note that this method only works with file paths (not, for example, string representations of URLs).

stringByDeletingLastPathComponent

关于ios - NSFileManager 如何返回文件路径的文件夹名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23470694/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com