如何获取文件夹的 .ext 目录

发布于 2024-11-19 03:54:45 字数 918 浏览 5 评论 0 原文

我正在创建一个 iPhone 应用程序,用于访问 iPhone 上具有随机扩展名的文件夹。例如:folder.g1Polt 。现在我可以访问此文件夹,因为我通过查看我的文件知道我的 .ext,但它仅适用于我的设备。如何检索实际 .ext 的 isDir 下面您可以看到从该文件夹检索文件的工作代码,但我需要删除该 .g1Polt 并只有

NSString *path = @"/private/var/stash/主题/”;

NSString *path = @"/private/var/stash/Themes.g1Polt/";
contentOfFolder = [[NSFileManager defaultManager] directoryContentsAtPath:path];
NSLog(@"contentOfFolder: %@", contentOfFolder);
directoriesOfFolder = [[NSMutableArray alloc] initWithCapacity:100];
for (NSString *aPath in contentOfFolder) {
    NSString * fullPath = [path stringByAppendingPathComponent:aPath];

    BOOL isDir;
    if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir] &&  
isDir) {
        [directoriesOfFolder addObject: fullPath];
    }
}
NSLog(@"dirctories %@", directoriesOfFolder);    

[directoriesOfFolder addObjectsFromArray:contentOfFolder];

I am creating a iPhone Application that accesses a Folder on the iPhone that has a random extension. For example: folder.g1Polt . Now I have access to this folder since I know my .ext by looking into my files, but it will only work for MY device. How can I retrieve isDir for the actual .ext Below you can see the working code that retrieves the files from this folder but I need to get rid of that .g1Polt and have just

NSString *path = @"/private/var/stash/Themes/";

NSString *path = @"/private/var/stash/Themes.g1Polt/";
contentOfFolder = [[NSFileManager defaultManager] directoryContentsAtPath:path];
NSLog(@"contentOfFolder: %@", contentOfFolder);
directoriesOfFolder = [[NSMutableArray alloc] initWithCapacity:100];
for (NSString *aPath in contentOfFolder) {
    NSString * fullPath = [path stringByAppendingPathComponent:aPath];

    BOOL isDir;
    if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir] &&  
isDir) {
        [directoriesOfFolder addObject: fullPath];
    }
}
NSLog(@"dirctories %@", directoriesOfFolder);    

[directoriesOfFolder addObjectsFromArray:contentOfFolder];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肤浅与狂妄 2024-11-26 03:54:45

确实不清楚您想要实现什么目标。

我可以告诉您的是,您将无法访问 iPhone 上沙箱之外的文件,因此您无论如何也无法访问这些文件。请参阅Apple 文档 了解有关沙箱的更多信息

基本上,您应该在自己的 Documents 目录中工作。

It really is not clear what you are trying to achieve.

What I can tell you is that you will no be able to access files outside of your sandbox on the iPhone so you will not be able to get to those files anyway. See the Apple docs for more on the sandbox

Basically you should be working within your own Documents directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文