How to get the filename only out of an ALLEGRO_FS_ENTRY
Frank Drebin


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

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);


I think you need to go via ALLEGRO_PATH, which has a al_get_path_filename for this purpose.

Frank Drebin

Thanks for your ideas.
Edgar, your approach seems to work using <string>.

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

I recently added a FileSystem to my eagle library, which takes care of all these kind of things for you.

Thread #617445. Printed from