Question

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.

Was it helpful?

Solution

NSSearchPathForDirectoriesInDomains() is a low level API that should be avoided unless you need it for some unusual reason. Instead you should be using 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. You should use the URLsForDirectory:inDomains: method instead.

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.

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 is generally faster and less buggy reliable and uses less RAM than using strings. Often it uses low level filesystem/sector references.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top