How to get file name from a full path
-
Don Box wrote:
still I'll strongly recommend u to try writing such function.
Less u write, less will be the bugs...
nave [OpenedFileFinder]
-
Though some API's have been mentioned above by our codeproject friends, u can also write such functions. If u know 'C' language very well and ofcourse, its basics (people having lot of experience also doesn't know the basics), u can easily write such functions. Though u got the API, still I'll strongly recommend u to try writing such function.
Come online at:- jubinc@skype
I do have written a function to do make the job done, but I still want to know is there some exist functions can do this job for me. :)
A Chinese VC++ programmer
-
If basics are not clear and don't have confidence, then better don't write (such simple function) and drop the programming profession.
Come online at:- jubinc@skype
cool man..I just said one truth regrding the programming field. How ever I still remeber one bug while trying to extract the file name from path. We were extracting the file name by reverse finding the "\". But later a bug was reported and reason was that, in one secnario in the path input to that function, instead of "\", seperator was "/" :(
nave [OpenedFileFinder]
-
cool man..I just said one truth regrding the programming field. How ever I still remeber one bug while trying to extract the file name from path. We were extracting the file name by reverse finding the "\". But later a bug was reported and reason was that, in one secnario in the path input to that function, instead of "\", seperator was "/" :(
nave [OpenedFileFinder]
-
I do have written a function to do make the job done, but I still want to know is there some exist functions can do this job for me. :)
A Chinese VC++ programmer
-
Don Box wrote:
still I'll strongly recommend u to try writing such function.
Less u write, less will be the bugs...
nave [OpenedFileFinder]
Naveen wrote:
Less u write, less will be the bugs...
Write no code and you'll have absolutely no bugs. :-\
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Suppose the full path is :
C:\Program Files\codeproject.txt
I want to extract the file namecodeproject.txt
. Of course I can use CString class to find the last '\', and then Mid to get the filename, but is there some API can do this daily job? Thank you :)A Chinese VC++ programmer
You may use
PathFindFileName()
like this:TCHAR \*szPath = \_T("C:\\\\Program Files\\\\codeproject.txt"); AfxMessageBox(PathFindFileName(szPath));
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Suppose the full path is :
C:\Program Files\codeproject.txt
I want to extract the file namecodeproject.txt
. Of course I can use CString class to find the last '\', and then Mid to get the filename, but is there some API can do this daily job? Thank you :)A Chinese VC++ programmer
-
Thank you nave! I think I have got the answer
:_splitpath
:)A Chinese VC++ programmer
zengkun100 wrote:
I think I have got the answer:_splitpath
MSDN Says:
_splitpath
is deprecated because more secure versions are available, see_splitpath_s
, _wsplitpath_s
.Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Naveen wrote:
Less u write, less will be the bugs...
Write no code and you'll have absolutely no bugs. :-\
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Yes. but the damn requirments doesnt allow me to be like that :(
nave [OpenedFileFinder]
-
That's right Naveen. BTW, how many yrs of experience do u have in VC++? Do u have any Skype/Yahoo id?
Come online at:- jubinc@skype
Don Box wrote:
Do u have any Skype/Yahoo id?
Yahoo only... Have send my chat id to your mail box. check
nave [OpenedFileFinder]
-
Don Box wrote:
Do u have any Skype/Yahoo id?
Yahoo only... Have send my chat id to your mail box. check
nave [OpenedFileFinder]
-
Naveen wrote:
Yahoo only... Have send my chat id to your mail box. check
To my which e-mail id? If it is skype, then there's no mail box for this. Its my skype id (just for chatting).
Come online at:- jubinc@skype
No I clicked "email" option in the message board. My chat id is nave432@yahoo.com
nave [OpenedFileFinder]
-
Suppose the full path is :
C:\Program Files\codeproject.txt
I want to extract the file namecodeproject.txt
. Of course I can use CString class to find the last '\', and then Mid to get the filename, but is there some API can do this daily job? Thank you :)A Chinese VC++ programmer
Hi, char szFilePath[MAX_PATH] = {"C:\\Program Files\\codeproject.txt"}; char szFileNameOnly = strrchr(szFilePath,'\\'); if(szFileNameOnly) szFileNameOnly++; now szFileName points to "codeproject.txt" i think this works fine for u.
-
Hi, char szFilePath[MAX_PATH] = {"C:\\Program Files\\codeproject.txt"}; char szFileNameOnly = strrchr(szFilePath,'\\'); if(szFileNameOnly) szFileNameOnly++; now szFileName points to "codeproject.txt" i think this works fine for u.
Nitheesh George wrote:
char szFileNameOnly = strrchr(szFilePath,'\\');
Good, but a small correction.
strrchr
returns a character pointer. :)Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
You may use
PathFindFileName()
like this:TCHAR \*szPath = \_T("C:\\\\Program Files\\\\codeproject.txt"); AfxMessageBox(PathFindFileName(szPath));
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Rajesh R Subramanian wrote:
PathFindFileName()
Thank you Rajesh R Subramanian I think this is the simplest way I have ever seen :-D
A Chinese VC++ programmer
-
Rajesh R Subramanian wrote:
PathFindFileName()
Thank you Rajesh R Subramanian I think this is the simplest way I have ever seen :-D
A Chinese VC++ programmer
zengkun100 wrote:
Thank you Rajesh
You're welcome. :)
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP