c++ - How to start explorer.exe with QProcess when the path to the specified file contains spaces?
问题描述
I want to start explorer and select a specific file. So I run
QProcess::startDetached(command);
with command set to
explorer.exe /select,C:\Users\....\file.txt
This works fine, but will fail if the path to the file contains spaces. But if I put the path in quotes
explorer.exe /select,"C:\Users\....\file.txt"
the explorer will open the documents folder and not the specified path. Running the same string from the command line works fine.
The string is initialized with
command = "explorer.exe" + "/select," + "\"" + QDir::toNativeSeparators(path) + "\"";
解决方案
如何做到这一点确实不是那么直观,但也不是不可能。
解决方案
将命令的所有参数 , 分解explorer.exe
为单独的字符串,即/select
, ,
, the_path
。
例子
QProcess::startDetached("explorer.exe", QStringList{"/select", ",", "C:\\Users\\Your Username\\Desktop\\Folder With Spaces\\file.txt"});
推荐阅读
- r - 使用 H2O 在 R 中平衡随机森林
- docker - 在大学实验室环境中管理 docker 容器
- python - 如何使用python检查文件是否包含电子邮件地址或md5
- bash - 使用命令扩展作为 `for` 循环的参数或初始化数组
- xamarin - Intel HAXM 与 Hyper-V 不兼容?
- php - 无法使用 BookedScheduler 发送电子邮件
- ruby-on-rails - 如何让 Active Admin 自定义排序工作?
- sas - SAS:如何检查导入的 Excel 工作表中的列是否包含字符串?
- powershell - 基于某些 OU 或 .CSV 文件将共享邮箱批量迁移到 Office 365 的 PowerShell 脚本
- javascript - 路径名包含从 Base64 解码字符串到使用 Prawn::Document 的图像的空字节错误