The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
(Android)How to determine whether path is directory
ancientcc
Guest

I want to add API to SDL.
SDL_bool SDL_IsDirectory(const char* dir)
SDL_bool SDL_IsFile(const char* file)

On android, SDL_IsFile uses AssetManager.open(), if success, it is true. But to SDL_IsDirectory, I cannot find proper method. I try to use AssetManager.list(), it too spend CPU, and have to give up.

Is there an effective method to determine path is directory?
(Android)How to determine whether path is directory
ancientli


Joined: 01 Jul 2015
Posts: 45
I want to add API to SDL.
SDL_bool SDL_IsDirectory(const char* dir)
SDL_bool SDL_IsFile(const char* file)

On android, SDL_IsFile uses AssetManager.open(), if success, it is true. But to SDL_IsDirectory, I cannot find proper method. I try to use AssetManager.list(), it too spend CPU, and have to give up.

Is there an effective method to determine the path is directory?
(Android)How to determine whether path is directory
Jonny D


Joined: 12 Sep 2009
Posts: 932
I think you can use stat(), but you have to use it on the actual file path because it won't do SDL's asset path magic:

bool ioIsDir(const char* filename)
{
    struct stat status;
    stat(filename, &status);


    return (status.st_mode & S_IFDIR);
}



Called as so:
snprintf(mybuffer, mybuffer_size, "%s/%s", SDL_AndroidGetInternalStoragePath(), "some_directory");

if(ioIsDir(mybuffer))
    ...




Jonny D






On Thu, Apr 7, 2016 at 10:17 AM, ancientcc wrote:
Quote:

I want to add API to SDL.
SDL_bool SDL_IsDirectory(const char* dir)
SDL_bool SDL_IsFile(const char* file)
 
On android, SDL_IsFile uses AssetManager.open(), if success, it is true. But to SDL_IsDirectory, I cannot find proper method. I try to use AssetManager.list(), it too spend CPU, and have to give up.
 
Is there an effective method to determine the path is directory?


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

(Android)How to determine whether path is directory
Jonny D


Joined: 12 Sep 2009
Posts: 932
(not sure about asset path, because I used SDL_AndroidGetInternalStoragePath(), which returns something more like a config path)

Jonny D




On Thu, Apr 7, 2016 at 10:29 AM, Jonathan Dearborn wrote:
Quote:
I think you can use stat(), but you have to use it on the actual file path because it won't do SDL's asset path magic:

bool ioIsDir(const char* filename)
{
    struct stat status;
    stat(filename, &status);


    return (status.st_mode & S_IFDIR);
}



Called as so:
snprintf(mybuffer, mybuffer_size, "%s/%s", SDL_AndroidGetInternalStoragePath(), "some_directory");

if(ioIsDir(mybuffer))
    ...




Jonny D






On Thu, Apr 7, 2016 at 10:17 AM, ancientcc wrote:


Quote:

I want to add API to SDL.
SDL_bool SDL_IsDirectory(const char* dir)
SDL_bool SDL_IsFile(const char* file)
 
On android, SDL_IsFile uses AssetManager.open(), if success, it is true. But to SDL_IsDirectory, I cannot find proper method. I try to use AssetManager.list(), it too spend CPU, and have to give up.
 
Is there an effective method to determine the path is directory?




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




(Android)How to determine whether path is directory
ancientli


Joined: 01 Jul 2015
Posts: 45
If access directory/file that not app’asset, use stat is OK. But if apply to asset, stat will fail.

The directory is on asset.