WebNov 15, 2012 · If data/is in the parent directory of your current Ruby file, go up twice: wb = Spreadsheet.open File.expand_path("../../data/zipcode_range.xls", __FILE__) The first ../always neutralizes the __FILE__when using File.expand_paththis way. If you are not sure, make a debugging output of the file path that was generated: WebObjects of class Dir are directory streams representing directories in the underlying file system. They provide a variety of ways to list directories and their contents. See also File. The directory used in these examples contains the two regular files ( config.h and main.rb ), the parent directory ( .. ), and the directory itself (. ). What’s Here
spreadsheet - Ruby get parent dir of current file - Stack Overflow
WebI don't recommend this approach, because it means the script will be executed even if you enter that directory for some reason that's unrelated to working on the project. I suggest having a specific function that changes to the project directory and sources the settings script. myproj () { cd /some/directory && . ./projectSettings.bash } WebYou can try cd /usr/bin or system ('cd /usr/bin') in your ruby code, but this will only change current directory of new shell (which is child process of ruby which is child of the shell), but this is pointless becouse I thing that you can't change the directory of parent process in *inx system. – jcubic Aug 4, 2010 at 22:27 how do cars get transported
Get the parent directory of a given file [duplicate]
WebMar 19, 2024 · Dir.pwd is equivalent to pwd -P. exec ('pwd -L') will get the equivalent of pwd in the terminal (pwd is normally a bash builtin, and doesn't resolve symbolic links). – Barry Kelly Jan 26, 2014 at 3:27 1 please take also a look to the often forgotten Pathname class: ruby-doc.org/stdlib-2.1.1/libdoc/pathname/rdoc/Pathname.html – awenkhh WebApr 16, 2024 · # to the directory where the script itself is located. # Note 2: you don't need to load any library to get access to Dir.pwd Sign up for free to join this conversation on GitHub . WebDec 19, 2011 · It is an expected behavior. The script is run in a subshell, and cannot change the parent shell working directory. Its effects are lost when it finishes. To change the current shell's directory permanently you should use the source command, also aliased simply as ., which runs a script in the current shell environment instead of a sub shell. how do cars die