问题
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:
- At application installation time, put the files at a directory inside of the user home dir ~/ (the home indirection also works in windows)
- 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