SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get the directory of the current script?

    Hi,

    How do I get the directory path of the file that is currently
    executing?

    Also, if I have a module, within a function, how do I get the parent
    directory (full path) of that module?

    Thanks

    Javi

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,047
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    I've never done it so I don't know for sure, but I've seen lines like
    Code Ruby:
    RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
    so I'm guessing there's a way to use __FILE__ to get the full path similar to getting the directory name.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to use the Dir class.
    Code:
    Dir.pwd
    http://ruby-doc.org/core/classes/Dir.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •