Are there any C APIs to extract the base file name from its full path in Linux? -


Looking at the full path, the API should give me the base file name Example, "/foo/bar.txt" -> "bar.txt".

is there

this is a path (a char * ) and this will give you the name of the base name (the file / directory you want), the form of another char * .

Edit:

I forgot to tell you that basename () modifies your argument if you want to avoid it You can use the GNU version of basename () in your source:

  #define _GNU_SOURCE #include & lt; String.h & gt;  basename ()  of this code in the exchange will return a blank string if you feed it, e.g.  

Comments