15 个解决方案
#1
CString ReserveFind('\\');
#2
从字符串尾部搜索 '\\'或者'\'
然后在截取相应的字符串
然后在截取相应的字符串
#3
CString GetAppPath()
{
TCHAR sExePath[MAX_PATH], sCurDir[MAX_PATH];
TCHAR drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH];
ZeroMemory(sExePath,MAX_PATH);
ZeroMemory(sCurDir,MAX_PATH);
ZeroMemory(drive,MAX_PATH);
ZeroMemory(dir,MAX_PATH);
ZeroMemory(fname,MAX_PATH);
ZeroMemory(ext,MAX_PATH);
GetModuleFileName(NULL,sExePath,MAX_PATH);
_tsplitpath_s(sExePath,drive, dir, fname, ext );
_tmakepath_s(sCurDir,drive,dir,NULL,NULL);
return sCurDir;
}
自己取你想要的东西
{
TCHAR sExePath[MAX_PATH], sCurDir[MAX_PATH];
TCHAR drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH];
ZeroMemory(sExePath,MAX_PATH);
ZeroMemory(sCurDir,MAX_PATH);
ZeroMemory(drive,MAX_PATH);
ZeroMemory(dir,MAX_PATH);
ZeroMemory(fname,MAX_PATH);
ZeroMemory(ext,MAX_PATH);
GetModuleFileName(NULL,sExePath,MAX_PATH);
_tsplitpath_s(sExePath,drive, dir, fname, ext );
_tmakepath_s(sCurDir,drive,dir,NULL,NULL);
return sCurDir;
}
自己取你想要的东西
#4
从后向前找\\
#5
一般用1楼方法,不过3楼的方法貌似很强大,没用过
#6
CString chName = 路径;
CString szName = "";
p = strrchr(chName,'\\');
p++;
szName.Format("%s",p);
CString szName = "";
p = strrchr(chName,'\\');
p++;
szName.Format("%s",p);
#7
顶一下一楼,虽然简单,但是却把主旨说了出来。
#8
PathRemoveFileSpec:获取路径
PathFindFileName:获取文件名
PathFindFileName:获取文件名
#9
strPath = strPath.ReverseFind("\\");
#10
#include <windows.h>
#include <stdio.h>
void main()
{
char path_buffer[_MAX_PATH]="c://123.exe";
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( path_buffer, drive, dir, fname, ext );
printf("%s%s",fname,ext);
}
#include <stdio.h>
void main()
{
char path_buffer[_MAX_PATH]="c://123.exe";
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( path_buffer, drive, dir, fname, ext );
printf("%s%s",fname,ext);
}
#11
#12
#3楼或#10楼的_splitpath即可
#13
来晚了_splitpath(W2A(cmd),drive, dir, fname,ext);
#14
^_^
#15
mark
#1
CString ReserveFind('\\');
#2
从字符串尾部搜索 '\\'或者'\'
然后在截取相应的字符串
然后在截取相应的字符串
#3
CString GetAppPath()
{
TCHAR sExePath[MAX_PATH], sCurDir[MAX_PATH];
TCHAR drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH];
ZeroMemory(sExePath,MAX_PATH);
ZeroMemory(sCurDir,MAX_PATH);
ZeroMemory(drive,MAX_PATH);
ZeroMemory(dir,MAX_PATH);
ZeroMemory(fname,MAX_PATH);
ZeroMemory(ext,MAX_PATH);
GetModuleFileName(NULL,sExePath,MAX_PATH);
_tsplitpath_s(sExePath,drive, dir, fname, ext );
_tmakepath_s(sCurDir,drive,dir,NULL,NULL);
return sCurDir;
}
自己取你想要的东西
{
TCHAR sExePath[MAX_PATH], sCurDir[MAX_PATH];
TCHAR drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH];
ZeroMemory(sExePath,MAX_PATH);
ZeroMemory(sCurDir,MAX_PATH);
ZeroMemory(drive,MAX_PATH);
ZeroMemory(dir,MAX_PATH);
ZeroMemory(fname,MAX_PATH);
ZeroMemory(ext,MAX_PATH);
GetModuleFileName(NULL,sExePath,MAX_PATH);
_tsplitpath_s(sExePath,drive, dir, fname, ext );
_tmakepath_s(sCurDir,drive,dir,NULL,NULL);
return sCurDir;
}
自己取你想要的东西
#4
从后向前找\\
#5
一般用1楼方法,不过3楼的方法貌似很强大,没用过
#6
CString chName = 路径;
CString szName = "";
p = strrchr(chName,'\\');
p++;
szName.Format("%s",p);
CString szName = "";
p = strrchr(chName,'\\');
p++;
szName.Format("%s",p);
#7
顶一下一楼,虽然简单,但是却把主旨说了出来。
#8
PathRemoveFileSpec:获取路径
PathFindFileName:获取文件名
PathFindFileName:获取文件名
#9
strPath = strPath.ReverseFind("\\");
#10
#include <windows.h>
#include <stdio.h>
void main()
{
char path_buffer[_MAX_PATH]="c://123.exe";
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( path_buffer, drive, dir, fname, ext );
printf("%s%s",fname,ext);
}
#include <stdio.h>
void main()
{
char path_buffer[_MAX_PATH]="c://123.exe";
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( path_buffer, drive, dir, fname, ext );
printf("%s%s",fname,ext);
}
#11
#12
#3楼或#10楼的_splitpath即可
#13
来晚了_splitpath(W2A(cmd),drive, dir, fname,ext);
#14
^_^
#15
mark