我试图用Ruby编写一个简单的程序,以便在Windows中打开一个特定的文件夹。我正在执行一个简单的系统调用来打开打开文件夹路径的资源管理器窗口。我想打开的路径是\AppData\Roaming\SketchUp\SketchUp 2014。
当我输入以下内容时:
explorer %userprofile%\AppData\Roaming\SketchUp\SketchUp 2014我的cmd窗口文件夹打开没有问题。当我将这个命令放入我的ruby脚本并在草图中正确地安装程序时,打开的文件夹就是用户的Documents文件夹。即使我指定了C:\Users\UserName yada yada yada的路径,它仍然只打开一个文件夹到Documents文件夹。我的Mac版的这个功能非常好。我在这里错过了什么?
发布于 2014-03-25 19:10:31
您还应该确保在Windows上使用反斜杠(\)作为路径分隔符,否则它将无法工作。这些反斜杠应该转义(即\\)。例如,要打开SketchUp\SketchUp 2014文件夹:
appdata = ENV['appdata']
path = [appdata, 'SketchUp', 'SketchUp 2014']
pathstr = path.join(File::ALT_SEPARATOR) # File::SEPARATOR == '/', we need "\\"
# => "C:\\Users\\<username>\\AppData\\Roaming\\SketchUp\\SketchUp 2014"
# Pass as argument to explorer call:
`explorer #{pathstr}`
# or
system("explorer #{pathstr}")
# or
system('explorer %s' % pathstr)发布于 2022-01-07 14:21:36
我尝试过您的语法André,但是弹出了一个窗口,它说没有任何应用程序可以打开这个URL。为了指明我想在Finder中打开路径的系统(在Mac上),而不是使用默认的web浏览器打开URL,我必须稍微修改您的代码:
UI.openURL("file:///#{path)}")发布于 2014-11-16 07:17:56
Sketchup Api有此工作的代码。对于sketchup中的作品,编写以下代码:
myPlugin_folder = Sketchup.find_support_file("Plugins")
UI.openURL(myPlugin_folder)希望这能帮到你。
https://stackoverflow.com/questions/22642520
复制相似问题