CCFileUtils::fullPathFromRelativePath on android

Hi!

Thanks for a nice cross platform port of Cocos2D. :slight_smile:

I’m trying to read files from the resources using the c functions opendir, readdir etc. I have a folder “maps” with some json files in it. On iOS I can get the full path to the “maps” folder by doing

const char *fullPath = CCFileUtils::fullPathFromRelativePath(path);

and then go listing the files and building my maps list UI. However, under android this doesn’t seem to work, opendir can find the folder “maps”. What am I doing wrong? :frowning:

Thanks

I’m not sure, but I think I readed on this forum that the apk files are “compressed”, so maybe you cannot read the files without “decompressing”. One solution could be rename your json files to .mp3 in order to not be compressed. Try it.

Thanks for the reply! I tried renaming some of the maps in the maps folder to .mp3 like you suggested but it isn’t helping since I have problems even finding the maps folder, I haven’t gotten to the files’ contents yet. I had forgotten about the compression tho, might have given me problems later on. :slight_smile:

So to clarify, I am not reading the files’ contents yet. Right now I’m only using opendir and readdir from dirent.h to open the directory “maps” from the resources and listing the file names of the json files I have in there. On iOS this works, opendir can find the “maps” folder when I do:

const char fullPath = CCFileUtils::fullPathFromRelativePath;

DIR
dir = opendir(fullPath);
if(DIR {

}
else {
// checking errno here
}

but on android the same code results in DIR == NULL and opendir sets the errno to ENOENT which, looking at http://pubs.opengroup.org/onlinepubs/7908799/xsh/opendir.html, means that “A component of dirname does not name an existing directory or dirname is an empty string.”.

Anyone know why this is happening?

Thanks for helping) :slight_smile:

I have tested further and can access files ending in “.json” in my “maps” folder. They are all named “001.json”, “002.json”, “003.json” and so on. I tried reading “011.json” and printing it’s data on both Android and iOS and it works on both.

I still haven’t figured out how to list the files in the “maps” folder programmatically on Android though but it still works on iOS. Android just doesn’t find the “maps” folder when I do

opendir(“maps”);

By the way, the path “maps” is what I get back on Android when I call

CCFileUtils::fullPathFromRelativePath(“maps”);

but on iOS I get a much longer path.

Thanks in advance. :slight_smile:

Is there something about how the resources work on Android that I am missing? Any expert out there? :slight_smile: