[英]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.