# Change to a newly created directory

**URL:** <https://www.ruby-forum.com/t/change-to-a-newly-created-directory/187430>\
**Category:** Ruby\
**Created:** [April 23, 2010, 1:24am UTC](https://www.ruby-forum.com/t/change-to-a-newly-created-directory/187430 "2010-04-23T01:24:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [April 23, 2010, 1:24am UTC](https://www.ruby-forum.com/t/change-to-a-newly-created-directory/187430/1 "2010-04-23T01:24:54Z")

</div>

Ruby Beginner

I have a command line script that captures a single argument and creates  
a directory in that name. I then want to copy some directories inside  
of this newly created directory.

I can’t seem to figure out how to change to the new directory.

require ‘FileUtils’

file\_name = ARGV[0]

FileUtils.mkdir file\_name # Creates top level directory

# I want this folder to be subdirectory of the newly created top-level

directory  
FileUtils.mkdir\_p ‘/images’

Thanks

John

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [April 23, 2010, 5:28am UTC](https://www.ruby-forum.com/t/change-to-a-newly-created-directory/187430/2 "2010-04-23T05:28:10Z")

</div>

you can try:

file\_path = ARGV[0]

FileUtils.mkdir\_p file\_path + ‘/images’

John W. wrote:

> Ruby Beginner
> 
> I have a command line script that captures a single argument and creates  
> a directory in that name. I then want to copy some directories inside  
> of this newly created directory.
> 
> I can’t seem to figure out how to change to the new directory.
> 
> require ‘FileUtils’
> 
> file\_name = ARGV[0]
> 
> FileUtils.mkdir file\_name # Creates top level directory
> 
> # I want this folder to be subdirectory of the newly created top-level
> 
> directory  
> FileUtils.mkdir\_p ‘/images’
> 
> Thanks
> 
> John

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [April 23, 2010, 2:16pm UTC](https://www.ruby-forum.com/t/change-to-a-newly-created-directory/187430/3 "2010-04-23T14:16:10Z")

</div>

Dir.chdir(directory\_name)

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [April 24, 2010, 9:08pm UTC](https://www.ruby-forum.com/t/change-to-a-newly-created-directory/187430/4 "2010-04-24T21:08:08Z")

</div>

Great! thanks for your help.

John
