简体   繁体   English

如何在Obj-c中获取搜索文件夹的父目录?

[英]How to get the parent directory of a searched folder in Obj-c?

I was wondering how to get an app name from /var/mobile/Applications (iOS) but the .app folders are within unique directory names. 我想知道如何从/ var / mobile / Applications(iOS)获取应用程序名称,但是.app文件夹位于唯一的目录名称内。

I was wondering how (or if) I could parse a search on all the folders' child directories for a folder named eg Messenger.app and return the parent directory (the unique, long folder name it's stored in). 我想知道如何(或是否)可以在所有文件夹的子目录中解析一个名为Messenger.app的文件夹的搜索,然后返回父目录(存储在其中的唯一的长文件夹名称)。

eg The user has 3 apps installed from the App store, One is Facebook.app, another is Twitter.app and the other one is called Messenger.app. 例如,用户从App Store安装了3个应用程序,一个是Facebook.app,另一个是Twitter.app,另一个是Messenger.app。 They are installed to /var/mobile/Applications with unique IDs such as 1183472234-DDFGHSF-33442/AppName.app Search for app name Messenger.app within /var/mobile/Applications/* and return the parent directory (eg 1183472234-DDFGHSF-33442) 它们被安装到具有唯一ID(例如1183472234-DDFGHSF-33442 / AppName.app)的/ var / mobile / Applications中,在/ var / mobile / Applications / *中搜索应用程序名称Messenger.app并返回父目录(例如1183472234-DDFGHSF -33442)

Is there any way how to do this? 有什么办法吗?

Edit : are you talking about your own app, or other apps? 编辑 :您是在谈论自己的应用还是其他应用?

You can access the "documents directory" for your app, and then see the full path. 您可以访问应用程序的“文档目录”,然后查看完整路径。 This is how you can get to the documents directory: 这是您到达documents目录的方式:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

Now you have your path stored in a NSString called "documentsDirectory". 现在,您已将路径存储在名为“ documentsDirectory”的NSString中。 Simply output documentsDirectory to the log or parse it to get the unique directory name. 只需将documentsDirectory输出到日志中或对其进行解析即可获得唯一的目录名称。 Here is an example output for me: 这是我的示例输出:

NSLog(@"%@", documentsDirectory);

----

/Users/John/Library/Application Support/iPhone Simulator/5.1/Applications/CBCEF6C0-3CFE-46EC-BD42-5969104B69D0/Documents

I'm using the iOS Simulator, but it will work on real devices as well. 我正在使用iOS Simulator,但它也可以在真实设备上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM