繁体   English   中英

使用默认应用程序打开名称中带有空格(或&)的文件

[英]open file that has a space (or &) in its name, with default app

我正在尝试打开一个文件,其路径为C:\\ Users \\ kevin \\ Documents \\ LIN KED.png(或C:\\ Users \\ kevin \\ Documents \\ LIN&KED.png)。 文件路径将在linked_file_command中。

我想在Windows的默认应用程序中打开文件。 我想继续使用linked_file_command字符串,只是为了使用变量而不是硬编码路径。

我尝试了以下方法:

1) system %{cmd /c "start #{linked_file_command}"}
(from https://stackoverflow.com/questions/9476291/how-to-open-file-in-default-application-ruby )

2) system('cmd /c start "" C:\Users\kevin\Documents\LIN KED.png')
(from https://www.ruby-forum.com/topic/209961 )

两者的结果:

解决问题的方法C:\\ Users \\ kevin \\ Documents \\ LIN。 (系统找不到文件C:\\ Users \\ kevin \\ Documents \\ LIN)

在此先感谢^。^

这应该工作

filePath = "c:\path\to\file name.jpg"
system %{cmd /c "start #{filePath}"}

管理空间

system('cmd /c start "" "C:\\Users\\kevin\\Documents\\LIN KED.png"')

我在这里阅读superuser.com/questions/511486/…

第一个“”用于shell窗口名称,第二个“”用于命令(参数)

管理与

当我使用上面的行时不是必需的。

在其他情况下,请尝试在&符号前添加“ ^”

system('cmd /c start "" "C:\\Users\\kevin\\Documents\\LIN^&KED.png"')

from: 如何在批处理文件中转出“&”号?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM