我正在寻找一个特定的应用程序安装位置在注册表。由于InstallLocation没有我需要的值,所以我使用ImagePath获取物理路径。但是,我需要目录,而不是完整的路径。我得到的是:
(string) subkey.GetValue("ImagePath") =
"\"C:\\Program Files (x86)\\Some Folder\\Some Other Folder\\TheApplication.exe\""使用
Path.GetDirectoryName((string) subkey.GetValue("ImagePath"))引发以下错误。
路径中的非法字符。
这是因为额外的反斜杠吗?我试着用.Replace(@"\\", "\")删除那些,但没有运气。
发布于 2018-12-04 21:25:31
是引号导致Path.GetDirectoryName抛出异常。您可以对返回的值调用Trim以删除周围的引号。
string path = ((string)subkey.GetValue("ImagePath")).Trim('"');
string directoryName = Path.GetDirectoryName(path);https://stackoverflow.com/questions/53621007
复制相似问题