I am trying to run a command to open a specific location in the explorer.exe
and select a specific file:
QUrl url = QUrl::fromUserInput(file.absoluteFilePath());
QString str = "explorer.exe /select,\"" + url.toString() + "\"";
system(str.toStdString().c_str());
This works great with Windows locations.
But since I open as well locations from a NAS and MAC user can create folders there I have a problem with folders like this:
//NAS/FOLDER/With/BackSLASH/file.ext
Since it's possible on a Mac to use slashes for file/folder naming it cannot be recognized by the system()
funciton and QString
converts it to U+002F
.
In Windows explorer it is shown as:
FOLDER•With•BackSLASH
and, if I use the command prompt to navigate into such a folder it shows the folder name as following:
PRODUCER'S NOTES 86
Does anyone have an idea how to handle this special case or how to convert this path to a path which can be passed as argument for the explorer.exe
?
/* EDIT 08/31/2018*/
I changed my Code to:
#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('/', '\\'));
But this still doesn't solve the Problem with the Backslashes and Slashes in Folder/FileNames. Seems the conversion "filename.toStdString().c_str()" causes the Problem.
If i print (qDebug()) the path it looks like this: //NAS/Folder\uF022With\uF022BackSLASH/file.ext
I found this Question and this Solved my problem. QDesktopServices::openUrl with selecting specified file in explorer