Trying to access the “current dir” in a packaged Shoes app

情到浓时终转凉″ 提交于 2020-01-05 12:15:24

问题


I need to build an app which reads a file which is external to the Shoes package I'll be distributing it in.

In my app, Dir.pwd points to the temp dir (at least in Windows) where the script is unpacked to be ran. I've been trying to get the directory where the exe is running from, that is, the package I'm distributing.

The app needs to read a file which is distributed besides this package and then write another one in the same directory.

It seems that the Shoes runtime does not set any env variable with this directory either. Any pointers?

nachokb


回答1:


I run into this problem a while ago and hadn't file a straight solution. I ended up with two workarounds:

  1. At application installation time, put the files at a directory inside of the user home dir ~/ (the home indirection also works in windows)
  2. Package the files together with the shoes generated executable so that it is unzip at the same place as the app and therefore accessible with Dir.pwd

If you find another way, please point it out.




回答2:


Have you tried something like the following:

DIR = File.expand_path __FILE__

__FILE__ is a reference to the current file and File.expand_path gives you the full system path. Works in my shoes apps :-)

Shoes on!

Tobi



来源:https://stackoverflow.com/questions/8475988/trying-to-access-the-current-dir-in-a-packaged-shoes-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!