int length = sPath.GetLength(); CString sFileName; for (int i = length - 1; i > 0; i--) { if (_T('\\') == sPath.GetAt(i)) { sFileName = sPath.Right(length - i - 1); break; } }