如何将执行路径与文件路径和参数分开
How to separate a executing path to file path and parameter?
有这样的行
C:Program FilesRealtekAudioHDARAVCpl64.exe -s
在注册表项中
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun
现在,我想将绝对路径和参数从直线中分离出来。
如果线路是
C:Space DirDot.DirSample Name.Dot.exe param path."C:Space DirDot.DirSample Name.Dot.exe"
我应该用哪个分隔符来处理这行?是否有任何Windows API函数可以解决此问题?
您想要的函数在Windows中可以使用的标准C库中。
char theDrive[5],thePath[MAX_PATH],theFilename[MAX_PATH],theExtension[MAX_PATH];
_splitpath(theSCTDataFilename,theDrive,thePath,theFilename,theExtension);
您还可以使用类似这样的更通用的标记化函数,该函数接受任何字符串、一个char和一个CStringArray。。
void tokenizeString(CString theString, TCHAR theToken, CStringArray *theParameters)
{
CString temp = "";
int i = 0;
for(i = 0; i < theString.GetLength(); i++ )
{
if (theString.GetAt(i) != theToken)
{
temp += theString.GetAt(i);
}
else
{
theParameters->Add(temp);
temp = "";
}
if(i == theString.GetLength()-1)
theParameters->Add(temp);
}
}
CStringArray thePathParts;
tokenizeString("yourcomplexpathofstringsseparatedbyslashes",'/',&thePathParts);
这将为您提供一个CString数组(CStringArray对象),其中包含输入字符串的每个部分。只要你知道要在上面分割字符串的分隔符,你就可以使用这个函数来解析主要的块,然后再解析次要的块。
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 创建进程使用路径时出现错误事件:类型 "char *" 的 E0167 参数与类型 "LPWSTR" 的参数不兼容
- C 能够以其完整路径打开代码::块中的文件,但不能以相对路径作为命令行参数打开文件
- 从文件名中提取文件名,路径来自参数
- 使用 php 将带有命令行可执行文件路径的参数传递
- 如何将执行路径与文件路径和参数分开
- 向文件名参数(LPCSTR)添加预先声明的路径
- 从net.connman.Manager的GetService方法动态提取D-Bus参数和对象路径
- 添加文件路径参数
- Train_hog.cpp OpenCV 3.1 示例 - 无法传递正确的路径参数
- 缩短C++枚举成员的路径(使用 typedef 或 typename),以用作模板参数
- 更改系统命令参数的路径
- 如何将带有空格作为参数的路径添加到CreateProcess批处理文件中
- 如何在vc++中将路径作为参数传递到第二个应用程序中
- 在源文件中指定include前缀与在编译器的搜索路径参数中指定include前缀的优缺点是什么
- 如何将目录中所有具有完整路径的文件传递到execv中的参数数组
- 当构造函数具有相同的参数类型(文件路径)时,如何从数组创建(初始化)std::元组
- 在参数列表中使用绝对路径启动QProcess