/ Published in: Ruby
Ruby provides a platform independent way of displaying file paths. Here are a few common ways to show absolute and relative paths.
- #Platform independant way of showing a File path. Empty String ('') means the root
- puts File.join('', 'Users', 'chrisaiv', 'Desktop')
- #Provide the RELATIVE path of THIS file
- puts __FILE__
- #Provide an ABSOLUTE path
- puts File.expand_path(__FILE__)
- #Provide the RELATIVE directory where this path is located
- puts File.dirname(__FILE__)
- #"Moves Up" one directory and enter another folder
- puts File.join(File.dirname(__FILE__), '..', 'NML' )
- #Tell Ruby all the folders as to where to look for us. In this case, look within the /lib
- APP_ROOT = File.dirname(__FILE__)
- $:.unshift( File.join( APP_ROOT, 'lib') )
You need to login to post a comment.