rubyexewxrubyocra

Setting filepaths inside your .rb file when converted into an exe with ocra


I've had a lot of trouble getting one my wxruby scripts to use an image file I included in the exe with ocra. If I didn't have the original image file in the same directory as the exe, the exe wouldn't find the image.

shape = File.join('warning3.png' )

I wanted the script to find the image I included in the exe.


Solution

  • In the ocra documentation it mentions Dir.chdir File.dirname($0) but I didn't get what it meant when it was mentioned.

    If you need to use say an image file in your script you can make sure it works merely by having this Dir.chdir(File.dirname($0)) line before you try to use any of your images.

    For example in my app I'm using an image file and I couldn't get my exe to work if it wasn't in the same dir as the file but with the below it works anywhere so far.

    Dir.chdir(File.dirname($0))
    shape = File.join('warning3.png' )
    

    I think this sets the script's current directory to the exe's directory inside it? If I'm wrong please let me know!