Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to get the filename only out of an ALLEGRO_FS_ENTRY

This thread is locked; no one can reply to it. rss feed Print
How to get the filename only out of an ALLEGRO_FS_ENTRY
Frank Drebin
Member #2,987
December 2002
avatar

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
avatar

SiegeLord
Member #7,827
October 2006
avatar

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
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Frank Drebin
Member #2,987
December 2002
avatar

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:

#SelectExpand
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
avatar

Go to: