| | |
Extract the file name from the full file path.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
> if(ss.ReverseFind('\\')== 8) What does this return if there is no \\ ? I've try something like this also,
C++ Syntax (Toggle Plain Text)
CString aa = fileName.Right(fileName.GetLength() - (fileName.ReverseFind('\\') + 1));
Actually it gives the file path. Then use ReverseFind() again and find the '.', use a Left() to get the name only.
As you say, if the extension is missing this wont work.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Solved Threads: 0
std::wstring PathToFileName(std::wstring strPath)
{
size_t found1 = strPath.rfind(L'\\');
size_t found2 = strPath.rfind(L'/');
size_t found = (found1!=std::wstring::npos) ? ( (found2!=std::wstring::npos) ? max(found1,found2) : found1 ) : found2;
std::wstring result = strPath.substr(found+1, strPath.length() - found-5);
return result;
}
{
size_t found1 = strPath.rfind(L'\\');
size_t found2 = strPath.rfind(L'/');
size_t found = (found1!=std::wstring::npos) ? ( (found2!=std::wstring::npos) ? max(found1,found2) : found1 ) : found2;
std::wstring result = strPath.substr(found+1, strPath.length() - found-5);
return result;
}
![]() |
Similar Threads
- Unable to open Web Project '...'. The file path '...' does not correspond to the URL (ASP.NET)
- Unable to open Web Project '...'. The file path '...' does not correspond to the URL (Community Introductions)
- please help me remove winfix. here is my log file from Hijack this (Viruses, Spyware and other Nasties)
- getting rid of Admilliserve log file (Viruses, Spyware and other Nasties)
- About;Blank Please Help, Hijack Log File (Viruses, Spyware and other Nasties)
- How to write a header file (C++)
- ASP locating file at client side (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: point inside triangle any situations where my code will fail?
- Next Thread: C++ postfix to infix help!
Views: 14749 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






