从文件路径获得文件名

	//获取文件路径
	WCHAR *FilePath = xxx;  //这里是你自己的路径 自己填值
	WCHAR FileName[MAX_PATH] = {
    
    0};
	//获取文件名
	LPWCH  find = wcsrchr(FilePath, '\\');  //倒序查找最后一个\
	if (!find)
	{
    
    
		MessageBox(L"未找到字符\\", L"提示", MB_OK | MB_ICONERROR);
		return;
	}
	//找出要复制字符的大小
	LPWCH NextFind = wcsrchr(FilePath, '.');
	if (!NextFind)
	{
    
    
		MessageBox(L"未找到文件扩展名", L"提示", MB_OK | MB_ICONERROR);
		return;
	}
	DWORD CopySize = (DWORD)(NextFind - find);

	//复制前清0
	ZeroMemory(FileName,MAX_PATH);
	memcpy_s(FileName, MAX_PATH, find + 1, CopySize*2-2);

猜你喜欢

转载自blog.csdn.net/qq_41490873/article/details/108550695