# How to move a file from one folder to another folder

**URL:** <https://www.ruby-forum.com/t/how-to-move-a-file-from-one-folder-to-another-folder/117052>\
**Category:** Rails\
**Created:** [October 12, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/how-to-move-a-file-from-one-folder-to-another-folder/117052 "2007-10-12T13:42:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [October 12, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/how-to-move-a-file-from-one-folder-to-another-folder/117052/1 "2007-10-12T13:42:29Z")

</div>

Hi all,

I want to move the file from one folder to another folder, but i  
don;t which command to use it, please let me know, if anybody knows  
my present coding is,

Dir["#{dirname}/ **/**"].each do | thisfile |  
thisfile.gsub! ( /// , ‘\’ )  
results.push ( thisfile )  
f = File.open(thisfile,“r”)  
@aread=f.read()

// after reading here i want to move the present file to another  
directory.

end

please help me to do this.

---

<div class="post-metadata">

**Author:** ![vidyagayathri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ba9def/32.png) [@vidyagayathri](https://www.ruby-forum.com/u/vidyagayathri)\
**Post date:** [October 12, 2007, 11:37pm UTC](https://www.ruby-forum.com/t/how-to-move-a-file-from-one-folder-to-another-folder/117052/2 "2007-10-12T23:37:09Z")

</div>

On 10/12/07, Vidya V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> I want to move the file from one folder to another folder

Use File.rename() or FileUtils.mv()

The first one won’t move to a different disk. The second one will.

HTH
