DOS used to have a 'splitpath' function which returned the various components of a full path.
Or you could do
- find the last \ to mark the start of the filename
- find the last . to mark the end of the filename.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Actually, you should probably Read This! , then post back.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
> Can you tell me about this more. Any worked example really appreciate.
What did your last slave die of?
Are you totally incapable of digging around in the manual pages to see what the CString API is capable of, or do you have to be told every single detail in advance before you try to use it?
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
OMG why in the world are you doing that just to extract the name part of the string! If the CString already contains the full path + filename just use its Find() method to locate the last '\' and you have the name starting with the next character.
>>That mean I have to cast CString to a char buffer, is that right? Is it possible?
Depends -- is your program compiled for UNICODE or not. If it is, then CString can not be simply typecase, it must be converted from wchar_t* to char* with one of the conversion functions.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
> if(ss.ReverseFind('\\')== 8)
What does this return if there is no \\ ?
In other words, do something like
int pathStart = ss.ReverseFind('\\');
if ( pathStart >= 0 ) {
// using the position and length of the string, you can now do say
aa = ss.Right(12);
// but replace the 12 with some kind of calculation based on the dynamic
// results you've calculated so far
}
Also, don't assume that the extension is
a) always present
b) always 3 characters.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Like I said, read the manual and find out what is returned when there is nothing to find, and use the appropriate if / else constructs to deal with it.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953