Given the full path, the API should give me the base file name. E.g., “/foo/bar.txt” –> “bar.txt”.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s basename() .
Feed it with a path (in the form of a
char*) and it will return you the base name (that is the name of the file/directory you want) in the form of anotherchar*.EDIT:
I forgot to tell you that the POSIX version of
basename()modifies its argument. If you want to avoid this you can use the GNU version ofbasename()prepending this in your source:In exchange this version of
basename()will return an empty string if you feed it with, e.g./usr/bin/because of the trailing slash.