What is the simplest way to get the file name that from a path?
string filename = "C:\\MyDirectory\\MyFile.bat"
In this example, I should get “MyFile”. without extension.
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.
_splitpath should do what you need. You could of course do it manually but
_splitpathhandles all special cases as well.EDIT:
As BillHoag mentioned it is recommended to use the more safe version of
_splitpathcalled _splitpath_s when available.Or if you want something portable you could just do something like this