I understand I can get current directory by
$CurrentDir = Dir.pwd
How about parent directory of current directory?
pwd : To check the current working directory, pwd(present working directory) method is used. 5. chdir : To change the current working directory, chdir method is used.
The dirname() function takes a pointer to a character string that contains a path name, and returns a pointer to a string that is a path name of the parent directory of that file. Trailing '/' characters in the path are not counted as part of the path.
__dir__ is a alias to a function As the ruby documentation says __dir__ is equal to File.dirname(File.realpath(__FILE__))
The root directory contains all other folders and files. Every directory, except the root directory, lies beneath another directory. The directory containing the current directory is called the parent directory, and the directory located within the current directory is called a subdirectory.
File.expand_path("..", Dir.pwd)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With