# Problem ruby pwd in different directory

**URL:** <https://www.ruby-forum.com/t/problem-ruby-pwd-in-different-directory/188608>\
**Category:** Ruby\
**Created:** [May 14, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/problem-ruby-pwd-in-different-directory/188608 "2010-05-14T18:30:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gladenko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/43a26b/32.png) [@gladenko](https://www.ruby-forum.com/u/gladenko)\
**Post date:** [May 14, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/problem-ruby-pwd-in-different-directory/188608/1 "2010-05-14T18:30:21Z")

</div>

Hi my problem is this

i have a script in direcory ex

c:\temp\pippo.rb

this script have this code

a= Dir.pwd()  
puts a

if i exec a script from another directory there is a problem. The script  
write a path of ruby exec and not the path of script ex

c:\nano\ruby …\temp\pippo.rb

=\> c:\nano

i want

=\> c:\temp

Can you help me???

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![gladenko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/43a26b/32.png) [@gladenko](https://www.ruby-forum.com/u/gladenko)\
**Post date:** [May 14, 2010, 6:58pm UTC](https://www.ruby-forum.com/t/problem-ruby-pwd-in-different-directory/188608/2 "2010-05-14T18:58:45Z")

</div>

On Fri, May 14, 2010 at 1:30 PM, Gianluca R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> c:\temp
> 
> Can you help me???

Dir.pwd gives the current working directory. To get the directory of  
the script you are running you can use File.dirname( **FILE** )

---

<div class="post-metadata">

**Author:** ![gladenko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/43a26b/32.png) [@gladenko](https://www.ruby-forum.com/u/gladenko)\
**Post date:** [May 14, 2010, 7:38pm UTC](https://www.ruby-forum.com/t/problem-ruby-pwd-in-different-directory/188608/3 "2010-05-14T19:38:14Z")

</div>

Luis P. wrote:

> On Fri, May 14, 2010 at 1:30 PM, Gianluca R.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > =\> c:\temp
> > 
> > Can you help me???
> 
> Dir.pwd gives the current working directory. To get the directory of  
> the script you are running you can use File.dirname( **FILE** )

Yessss Thank you very much! now is all ok!

😃

---

<div class="post-metadata">

**Author:** ![gladenko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/43a26b/32.png) [@gladenko](https://www.ruby-forum.com/u/gladenko)\
**Post date:** [May 15, 2010, 4:28am UTC](https://www.ruby-forum.com/t/problem-ruby-pwd-in-different-directory/188608/4 "2010-05-15T04:28:19Z")

</div>

On Fri, May 14, 2010 at 11:30 AM, Gianluca R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> =\> c:\temp
> 
> Can you help me???
> 
> ## Thank you in advance!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Hi, not entirely sure why you need the directory the same as the file,  
but  
every time I’ve needed that, it had to do with relative positioning of  
files. If that’s the case for you, then you might check out this blog  
entry,  
which I found pretty helpful

> **[Tip: Relative paths with File.expand\_path - Tom Ward's Blog](https://tomafro.net/2010/01/tip-relative-paths-with-file-expand-path)**
>
> Tom Ward's personal website
