欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

分割文件全路径中的目录与文件名(C语言,windows内核)

程序员文章站 2022-06-12 10:09:35
...

函数定义



//分割目录全路径与文件名
VOID SplitString(PUNICODE_STRING FullPath ,PWCHAR filePath ,WCHAR fileName[])
{
	PWCHAR p = FullPath->Buffer;
	int i = wcslen(p) -1;
	int count = i;
	int j = 0;
	while(p[i] != '\\')
	{
		fileName[j] = p[i];
		i--;
		j++;
	}
	WCHAR tmp ;
	int k = 0;
	int lenght = wcslen(fileName);
	for (j=lenght-1;k<j;k++,j--)
	{

		tmp = fileName[k];
		fileName[k] = fileName[j];
		fileName[j] = tmp;
	}
	//KdPrint(("fileName =%S\n",fileName));

	//WCHAR filepath_tmp[260] ={0};
	j = 0;
	for (i = 0;i < count-lenght;i++)
	{
		filePath[j] = p[i];
		j++;
	}
}

以下是调用


	  WCHAR fileName[260] = {0};
	  WCHAR filePath[260] = {0}; 
	  SplitString(&nameInfo->Name,filePath,fileName); //&nameInfo->Name 是文件全路径信息
	  KdPrint(("&nameInfo->Name = %wZ\n",&nameInfo->Name));