<分区>
我正在尝试运行命令以打开 explorer.exe
中的特定位置并选择特定文件:
QUrl url = QUrl::fromUserInput(file.absoluteFilePath());
QString str = "explorer.exe /select,\"" + url.toString() + "\"";
system(str.toStdString().c_str());
这适用于 Windows 位置。
但是因为我也从 NAS 和 MAC 用户打开位置,可以在那里创建文件夹,所以我遇到这样的文件夹问题:
//NAS/FOLDER/With/BackSLASH/file.ext
由于在 Mac 上可以使用斜杠来命名文件/文件夹,因此 system()
函数无法识别它,QString
将其转换为 U +002F
.
在 Windows 资源管理器中显示为:
FOLDER•With•BackSLASH
而且,如果我使用命令提示符导航到这样的文件夹,它会显示如下文件夹名称:
PRODUCER'S NOTES 86
有没有人知道如何处理这种特殊情况或如何将此路径转换为可作为参数传递给 explorer.exe
的路径?
/* 编辑 08/31/2018*/
我将代码更改为:
#include <Shlobj.h>
#include <atlstr.h>
void exportManager::BrowseToFile(QString filename)
{
TCHAR tchar[512];
USES_CONVERSION;
_tcscpy(tchar, A2T(filename.toStdString().c_str()));
ITEMIDLIST *pidl = ILCreateFromPath(tchar);
if (pidl) {
SHOpenFolderAndSelectItems(pidl, 0, 0, 0);
ILFree(pidl);
}
}
....
QString path = qFile.absoluteFilePath();
BrowseToFile(path.replace('/', '\\'));
但这仍然没有解决文件夹/文件名中反斜杠和斜杠的问题。 似乎是转换“filename.toStdString().c_str()”导致了问题。
如果我打印 (qDebug()) 路径,它看起来像这样: //NAS/文件夹\uF022With\uF022BackSLASH/file.ext
我发现了这个问题,这解决了我的问题。 QDesktopServices::openUrl with selecting specified file in explorer