Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] Questions regarding the "File System Routines"

Credits go to Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] Questions regarding the "File System Routines"
TeaRDoWN
Member #8,518
April 2007
avatar

1. How to get file names without their paths?
The al_get_fs_entry_name() return the full path+name of a file or directory, not only the name.
Is it possible to get only the name or do I simply have to trim the string myself? What I get is: "mods\AAL2D\gfx\ingame\blood.png" and what I want: "blood.png".

2. Can I filter the result on specific file extensions?
In A4 it was possible to filter the result by entering a specific file extension into al_findfirst().
I do not see anything like that in A5 when looking in the manual and examples. Do I have to filter this myself by comparing last part of string?

Arthur Kalliokoski
Second in Command
February 2005
avatar

TeaRDoWN said:

1. How to get file names without their paths?

basename()

Quote:

2. Can I filter the result on specific file extensions?

If you click on your own link al_findfirst(), it gives an example of searching for pcx files.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

torhu
Member #2,727
September 2002
avatar

There is an al_get_path_basename() function, if you want something more portable than basename. You would then have to create (and destroy) a temporary ALLEGRO_PATH.

Todd Cope
Member #998
November 2000
avatar

  1. You can use the path routines. al_get_path_filename() will get the filename.

  2. A5 does not provide a way to filter by extension.

Thomas Fjellstrom
Member #476
June 2000
avatar

And if you already have an ALLEGRO_PATH for the file, you can use al_get_path_extension() to get the extension :)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

TeaRDoWN
Member #8,518
April 2007
avatar

Arthur: I know that you filter with al_findfirst() but it is an A4 function and does not exist in A5 which I've moved over to.

Ok, thank guys for the answers. I'll use the al_get_path... functions to get the name and to filter on the extension.

Go to: