2

I have written virtual system (VFS) that I am using for my apps on Windows. Now, I moved my application to iOS and I have issue with dirrent.

Windows port has added info about current folder, where file is.

DIR * dir = opendir(dirName);
char * dirFullPath = dir->patt; //this is missing at iOS

How can I get that info ? DirName variable is useless, since its only relative path.

And second, on windows I specify folder to be mapped as root of my VFS. How can I do the same for iOS ? Lets say, to map VFS to directory DATA.

4

2 回答 2

1

NSSearchPathForDirectoriesInDomains() 是一个低级 API,应该避免使用,除非您出于某些不寻常的原因需要它。相反,您应该使用 NSURL。这是苹果官方的推荐:

NSSearchPathForDirectoriesInDomains 函数的行为类似于 URLsForDirectory:inDomains: 方法,但将目录的位置作为基于字符串的路径返回。您应该改用 URLsForDirectory:inDomains: 方法。

它是这样使用的:

NSURL *documentsURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject;

NSURL 对象完全符合您的要求:它是一个包含基本 URL 和其下的相对 URL 的对象。

如果您正在编写跨平台应用程序,则需要为非跨平台的所有内容编写包装器,并且文件系统操作是您需要抽象的事情之一。围绕 NSURL 和 NSFileManager 编写一个 C++ 包装器,并让你的包装器在其他平台上使用其他东西。

与使用字符串相比,NSURL 通常更快,错误更少,并且使用更少的 RAM。通常它使用低级文件系统/扇区引用。

于 2013-08-25T08:40:52.797 回答
0

请参阅`NSFileManager,因为它为文件系统提供了标准的 iOS 接口。

https://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

同样,您应该彻底了解这一点。

https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemProgrammingGuide.pdf

(参见 iOS 部分)

于 2013-08-24T17:06:19.783 回答