简体   繁体   English

iOS-dirent.h-当前目录名称

[英]iOS - dirent.h - current directory name

I have written virtual system (VFS) that I am using for my apps on Windows. 我已经编写了用于Windows上的应用程序的虚拟系统(VFS)。 Now, I moved my application to iOS and I have issue with dirrent. 现在,我将应用程序移至iOS,但目录问题。

Windows port has added info about current folder, where file is. Windows端口已添加有关当前文件夹(文件所在的位置)的信息。

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. DirName变量是无用的,因为它只是相对路径。

And second, on windows I specify folder to be mapped as root of my VFS. 其次,在Windows上,我指定要映射为VFS根目录的文件夹。 How can I do the same for iOS ? 如何在iOS上执行相同操作? Lets say, to map VFS to directory DATA. 可以说,将VFS映射到目录DATA。

NSSearchPathForDirectoriesInDomains() is a low level API that should be avoided unless you need it for some unusual reason. NSSearchPathForDirectoriesInDomains()是一个低级API,除非出于某些特殊原因需要它,否则应避免使用。 Instead you should be using NSURL. 相反,您应该使用NSURL。 This is Apple's official recommendation: 这是苹果公司的官方建议:

The NSSearchPathForDirectoriesInDomains function behaves like the URLsForDirectory:inDomains: method but returns the directory's location as a string-based path. NSSearchPathForDirectoriesInDomains函数的行为类似于URLsForDirectory:inDomains:方法,但返回目录的位置作为基于字符串的路径。 You should use the URLsForDirectory:inDomains: method instead. 您应该改用URLsForDirectory:inDomains:方法。

It's used like this: 它的用法如下:

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

The NSURL object does exactly what you want: it's an object that contains a base URL and then a relative URL under that. NSURL对象完全可以满足您的要求:它是一个包含基本URL,然后包含相对URL的对象。

If you are writing a cross platform app you need to write a wrapper around everything that is not cross platform, and filesystem operations are one of the things you need to abstract. 如果要编写跨平台应用程序,则需要为非跨平台的所有内容编写包装器,并且文件系统操作是您需要抽象的内容之一。 Write a C++ wrapper around NSURL and NSFileManager, and have your wrapper use something else on other platforms. 围绕NSURL和NSFileManager编写一个C ++包装器,并在其他平台上使用其他包装器。

NSURL is generally faster and less buggy reliable and uses less RAM than using strings. 与使用字符串相比,NSURL通常更快,错误更少,并且使用的RAM更少。 Often it uses low level filesystem/sector references. 它通常使用低级文件系统/扇区引用。

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

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