Return to Snippet

Revision: 20135
at November 11, 2009 21:18 by chrisaiv


Updated Code
#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') )

Revision: 20134
at November 8, 2009 20:13 by chrisaiv


Initial Code
#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' )

Initial URL


Initial Description
Ruby provides a platform independent  way of displaying file paths.  Here are a few common ways to show absolute and relative paths.

Initial Title
Ruby: File Path Basics

Initial Tags
ruby

Initial Language
Ruby