|
How to get the filename only out of an ALLEGRO_FS_ENTRY |
Frank Drebin
Member #2,987
December 2002
|
Hi! As the title says: Is there a convenient way to obtain the filename only (including file extension) out of an ALLEGRO_FS_ENTRY? Let's say I have a file associated with an ALLEGRO_FS_ENTRY named 'myfile' then I can use al_get_fs_entry_name(myfile) to obtain the full path+filename+extension. Of course I could iterate through this string backwards until I find a '/' and copy the difference but I am wondering if there is an easier or built-in function for that... |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You're giving me the lulz man. std::string GetFileName(std::string path) { unsigned int slash = path.find_last_of("\/"); if (slash == std::string::npos) {return path;} return path.substr(slash); }
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SiegeLord
Member #7,827
October 2006
|
I think you need to go via ALLEGRO_PATH, which has a al_get_path_filename for this purpose. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Frank Drebin
Member #2,987
December 2002
|
Thanks for your ideas. Siegelord's apporach seems to do the job using allegro's built-in functions: 1ALLEGRO_PATH* mypath=al_create_path(al_get_fs_entry_name(myfile));
2printf("%s\n",al_get_path_filename(mypath));
3al_destroy_path(mypath);
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I recently added a FileSystem to my eagle library, which takes care of all these kind of things for you. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|