Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:42:00+00:00 2026-06-18T00:42:00+00:00

I am getting confused with the utility of the File Class methods as below:

  • 0

I am getting confused with the utility of the File Class methods as below:

 1. File::absolute_path
 2. File::realdirpath
 3. File::realpath
 4. File::expand_path

What I tried below:

irb(main):001:0> Dir.pwd
=> "C:/Users/Matt"
irb(main):002:0> Dir.chdir('D:\VB Script\excel_ie_wsh')
=> 0
irb(main):003:0> Dir.pwd
=> "D:/VB Script/excel_ie_wsh"
irb(main):005:0> File.realdirpath('\VB Script\excel_ie_wsh')
=> "/VB Script/excel_ie_wsh"
irb(main):006:0> File.realpath('\VB Script\excel_ie_wsh')
=> "/VB Script/excel_ie_wsh"
irb(main):007:0> File.absolute_path('\VB Script\excel_ie_wsh')
=> "D:/VB Script/excel_ie_wsh"
irb(main):008:0> File.realpath('readme.txt')
=> "D:/VB Script/excel_ie_wsh/readme.txt"
irb(main):009:0> File.realdirpath('readme.txt')
=> "D:/VB Script/excel_ie_wsh/readme.txt"
irb(main):012:0> File.absolute_path('readme.txt')
=> "D:/VB Script/excel_ie_wsh/readme.txt"
irb(main):013:0>

Questions:

  1. Why File.realdirpath and File.realpath produces the same output?
  2. How File.realpath differs from File.absolute_path?
  3. How does absolute_path(file_nam) differ from absolute_path(file_name[, dir_string] )?
  4. How does realdirpath(pathname) differ from realdirpath(pathname [,
    dir_string])
    ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:42:02+00:00Added an answer on June 18, 2026 at 12:42 am

    Why File.realdirpath and File.realpath produces the same output?

    As per the ruby-doc, the only difference between these two methods is whether or not the last component of the pathname must exist. realdirpath does not care, where as realpath will throw an exception.

    For example, when getting the path of a file that does not exist:

    irb(main):001:0> File.realpath('nonexistent.file')
    Errno::ENOENT: No such file or directory - H:/nonexistent.file
            from (irb):1:in `realpath'
            from (irb):1
            from C:/Ruby193/bin/irb:12:in `<main>'
    
    irb(main):002:0> File.realdirpath('nonexistent.file')
    => "H:/nonexistent.file"
    

    How File.realpath differs from File.absolute_path?

    I am not on a UNIX system to test this, but my guess is that the only difference is when the path starts the tilde (ie ~). In UNIX, the tilde represents the home directory. I assume the difference between the two methods is whether or not it expands the home directory or not.

    If you are on windows, it should not matter (ie there is no home directory shortcut).

    How does realdirpath(pathname) differ from realdirpath(pathname [, dir_string]) ?

    The ruby-doc states “If dir_string is given, it is used as a base directory for interpreting relative pathname instead of the current directory.” In other words, dir_string can be specified to override the starting point.

    For example, let us assume that:

    1. You are running irb from the root of your H: drive (ie this is your current directory)
    2. You have a sub-folder named ‘Folder’ (ie H:\Folder)

    Then you can see the difference:

    H:\>irb
    irb(main):001:0> File.realdirpath('test.txt')
    => "H:/test.txt"
    
    irb(main):002:0> File.realdirpath('test.txt', './Expense')
    => "H:/Expense/test.txt"
    

    You can see that the second statement locates the file with respect to the directory stated in dir_string.

    How does absolute_path(file_nam) differ from absolute_path(file_name[, dir_string] )?

    This is the same as the previous question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting confused with my C++ class structure below: A.h: class A{ }; A.cpp
I am getting confused with the Array methods below. Can anyone help me understand
I'm getting confused with class inheritance for css. I have this: <ul id='grok'> <li
I'm getting confused at how java works with everything being a class. I make
My javascript file is getting pretty big (3000+ lines) and I'm getting confused as
I am getting confused with the scenario of 2 classes implementing the same interface
I'm getting confused by bank switching in PIC assembler... This works for putting a
I'm getting confused re the range of options for development & deploying some simple
I am getting confused between TCP being Connection oriented and UDP being connectionless so
I'm getting confused in the doco how I should be setting up Ninject. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.