Home > Software engineering >  MFC, a path is known, how can I get him the path of the upper level?
MFC, a path is known, how can I get him the path of the upper level?

Time:11-09

GetModuleFileName get a path in m_path, how can I get him the path of the upper level?

CodePudding user response:

?????????

CodePudding user response:

PathRemoveFileSpec
 
#include
#include
# include "Shlwapi. H"
# pragma comment (lib, "shlwapi. Lib")

Void main (void)
{
//the Path to the include file spec.
Char buffer_1 []="C: \ \ TEST \ \ sample TXT".
Char * lpStr1;
LpStr1=buffer_1;

//Print the path with the file spec.
Cout & lt; <"The path with The file spec is:" & lt;
//Call to "PathRemoveFileSpec".
PathRemoveFileSpecA (lpStr1);

//Print the path with the file spec.
Cout & lt; <"\ nThe path with the file spec is:" & lt; }

OUTPUT:
==================
The path with The file spec is: C: \ TEST \ sample TXT

The path with The file spec is: C: \ TEST



CodePudding user response:


Pour find/\ and then cut the strings

CodePudding user response:

: the role of PathRemoveFileSpec function at the end of the file name and path backslash take out,

CodePudding user response:

# pragma comment (lib, "Shlwapi. Lib")

CodePudding user response:

Is
Char * slashAt=STRRCHR (" c: "(defFileName, '\' \ ');
If (slashAt) * slashAt=0;

CodePudding user response:

Fast USES the c + + 17 STD: : filesystem: : path: : parent_path ()
For you
 cstrings parent_path (m_path); 
Parent_path=parent_path. Left (strPath. ReverseFind (' \ \ ') + 1);