shoes4 icon indicating copy to clipboard operation
shoes4 copied to clipboard

Packaged App Working dir is /

Open janrenz opened this issue 8 years ago • 1 comments

If i package an app (tested under Mac OS) and i try to load some files that are part of the jar this files. Some debugging later i found out that the working Dir of the app is '/'

Dir.getwd printed '/', and this is not within the jars sandbox or so: Debugging alert:

alert(Dir.entries(Dir.getwd).flatten)
screen shot 2017-09-29 at 17 30 36

So how can i load files packaged in the jar with ruby. @PragTob Mabybe you can help you old teacher :)

janrenz avatar Sep 29 '17 15:09 janrenz

Hi @jprberlin! So it turns out that we can't guarantee a consistent working directory for packaged apps, especially between operating systems.

The recommendation for finding files that are within your package is to look for them relative to your source files:

# From some Ruby file in your project
file_to_read = File.read(File.join(__FILE__, "../other/file.rb"))

Images will automatically work relative to your application root by themselves when used with the Shoes image method, but other file types you'll need to handle yourself relatively. Does that make sense?

jasonrclark avatar Oct 01 '17 03:10 jasonrclark