Click here to Skip to main content
15,912,400 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGetPrivateProfileSection Pin
rp_suman8-Nov-07 20:41
rp_suman8-Nov-07 20:41 
AnswerRe: GetPrivateProfileSection Pin
Hamid_RT8-Nov-07 21:13
Hamid_RT8-Nov-07 21:13 
AnswerRe: GetPrivateProfileSection Pin
CPallini8-Nov-07 21:21
mveCPallini8-Nov-07 21:21 
QuestionKnow loggedon user from a Service? Pin
SOAD_8-Nov-07 20:26
SOAD_8-Nov-07 20:26 
AnswerRe: Know loggedon user from a Service? Pin
Blake Miller16-Nov-07 5:10
Blake Miller16-Nov-07 5:10 
GeneralRe: Know loggedon user from a Service? Pin
SOAD_20-Nov-07 2:25
SOAD_20-Nov-07 2:25 
GeneralRe: Know loggedon user from a Service? Pin
Blake Miller20-Nov-07 4:50
Blake Miller20-Nov-07 4:50 
QuestionExtract the file name from the full file path Pin
CodingLover8-Nov-07 16:41
CodingLover8-Nov-07 16:41 
Hi all,

Using my application I've found a file path anywhere on my machine and store the full path in a CString variable. That full path, like this,

"F:\\Files\\Read_File.txt"

What I want to do is, find the name of the file(without the extension), and then separate two words Read and File.

I have tried one thing. Use ReverseFind() method of CString class to find the last '\' sign. Then I used the Right() to get the required file name. I can use Right() easily because file name length is always fixed.

<br />
CString ss = "F:\\Files\\ReadFile.txt";<br />
	CString aa;<br />
<br />
	if(ss.ReverseFind('\\')== 8)<br />
	{<br />
	AfxMessageBox(ss.Right(12), MB_OK);<br />
	aa = ss.Right(12);<br />
	}<br />
<br />
	if(aa.ReverseFind('.')==8)<br />
	{<br />
		AfxMessageBox(aa.Left(8), MB_OK);<br />
	}<br />


In this way I can separate those two words as well.

Actually this code gives the file name, ReadFile.

But there is a real issue, on the first 'if' condition. First part of the path, that is "F:\\Files" is not fixed. So in the first 'if' condition number 8 can be change depend on the file selection on my PC. How can avoid that.

Thanks

I appreciate your help all the time...
Eranga Smile | :)

AnswerRe: Extract the file name from the full file path Pin
Llasus8-Nov-07 16:59
Llasus8-Nov-07 16:59 
GeneralRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 17:24
CodingLover8-Nov-07 17:24 
GeneralRe: Extract the file name from the full file path Pin
Llasus8-Nov-07 17:35
Llasus8-Nov-07 17:35 
GeneralRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 17:55
CodingLover8-Nov-07 17:55 
GeneralRe: Extract the file name from the full file path Pin
Luc Pattyn8-Nov-07 18:00
sitebuilderLuc Pattyn8-Nov-07 18:00 
GeneralRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 18:10
CodingLover8-Nov-07 18:10 
GeneralRe: Extract the file name from the full file path Pin
Nelek8-Nov-07 21:52
protectorNelek8-Nov-07 21:52 
QuestionRe: Extract the file name from the full file path Pin
David Crow9-Nov-07 4:23
David Crow9-Nov-07 4:23 
GeneralRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 19:50
CodingLover8-Nov-07 19:50 
GeneralRe: Extract the file name from the full file path Pin
Llasus8-Nov-07 20:11
Llasus8-Nov-07 20:11 
GeneralRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 21:22
CodingLover8-Nov-07 21:22 
QuestionRe: Extract the file name from the full file path Pin
Hamid_RT8-Nov-07 20:17
Hamid_RT8-Nov-07 20:17 
AnswerRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 21:24
CodingLover8-Nov-07 21:24 
GeneralRe: Extract the file name from the full file path Pin
David Crow9-Nov-07 4:18
David Crow9-Nov-07 4:18 
AnswerRe: Extract the file name from the full file path Pin
Naveen8-Nov-07 18:07
Naveen8-Nov-07 18:07 
GeneralRe: Extract the file name from the full file path Pin
CodingLover8-Nov-07 18:54
CodingLover8-Nov-07 18:54 
GeneralRe: Extract the file name from the full file path Pin
Iain Clarke, Warrior Programmer9-Nov-07 4:33
Iain Clarke, Warrior Programmer9-Nov-07 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.