# Move a file

**URL:** <https://www.ruby-forum.com/t/move-a-file/173672>\
**Category:** Ruby\
**Created:** [August 13, 2009, 3:48am UTC](https://www.ruby-forum.com/t/move-a-file/173672 "2009-08-13T03:48:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bloodniece](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bloodniece](https://www.ruby-forum.com/u/bloodniece)\
**Post date:** [August 13, 2009, 3:48am UTC](https://www.ruby-forum.com/t/move-a-file/173672/1 "2009-08-13T03:48:07Z")

</div>

I looked around here and could not find a similar example. please help.  
My goal is to mv a file like so: mv /tmp/dev.log /usr/local/dev.log.tst  
using Ruby 1.8.7

ruby /tmp/test  
/tmp/test:8: syntax error, unexpected ‘)’, expecting kDO\_BLOCK

derek@derek-laptop:/tmp$ cat /tmp/test  
#!/usr/bin/env ruby -w  
require ‘ftools’;  
require ‘fileutils’;

file=“dev.log”  
FileUtils.cp("#{file}", “#{file}.copied”)  
ZIPDIR = “/usr/local/”  
FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")

---

<div class="post-metadata">

**Author:** ![bloodniece](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bloodniece](https://www.ruby-forum.com/u/bloodniece)\
**Post date:** [August 13, 2009, 5:26am UTC](https://www.ruby-forum.com/t/move-a-file/173672/2 "2009-08-13T05:26:43Z")

</div>

Hi,

Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek S.:

> ruby /tmp/test  
> /tmp/test:8: syntax error, unexpected ‘)’, expecting kDO\_BLOCK
> 
> FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")  
> ^^^

Try it with something like (untested)

“#{ZIPDIR}/#{file}.tst”  
File.join ZIPDIR, “#{file}.tst”

Syntax errors are the easiest to solve.

Bertram

---

<div class="post-metadata">

**Author:** ![bloodniece](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bloodniece](https://www.ruby-forum.com/u/bloodniece)\
**Post date:** [August 13, 2009, 6:27am UTC](https://www.ruby-forum.com/t/move-a-file/173672/3 "2009-08-13T06:27:01Z")

</div>

Bertram S. wrote:

> Hi,
> 
> Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek S.:
> 
> > ruby /tmp/test  
> > /tmp/test:8: syntax error, unexpected ‘)’, expecting kDO\_BLOCK
> > 
> > FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")  
> > ^^^
> 
> Try it with something like (untested)
> 
> “#{ZIPDIR}/#{file}.tst”  
> File.join ZIPDIR, “#{file}.tst”
> 
> Syntax errors are the easiest to solve.
> 
> Bertram

So in this line:

ZIPDIR"#{file}.tst"

you determined that you needed to use string interpolation for the  
variable file, but because ZIPDIR is capitalized, you didn’t think  
string interpolation was necessary for that variable, and instead you  
just wrote the variable next to the string?

---

<div class="post-metadata">

**Author:** ![bloodniece](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bloodniece](https://www.ruby-forum.com/u/bloodniece)\
**Post date:** [August 14, 2009, 1:46am UTC](https://www.ruby-forum.com/t/move-a-file/173672/4 "2009-08-14T01:46:48Z")

</div>

7stud – wrote:

> Bertram S. wrote:
> 
> > Hi,
> > 
> > Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek S.:
> > 
> > > ruby /tmp/test  
> > > /tmp/test:8: syntax error, unexpected ‘)’, expecting kDO\_BLOCK
> > > 
> > > FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")  
> > > ^^^
> > 
> > Try it with something like (untested)
> > 
> > “#{ZIPDIR}/#{file}.tst”  
> > File.join ZIPDIR, “#{file}.tst”
> > 
> > Syntax errors are the easiest to solve.
> > 
> > Bertram
> 
> So in this line:
> 
> ZIPDIR"#{file}.tst"
> 
> you determined that you needed to use string interpolation for the  
> variable file, but because ZIPDIR is capitalized, you didn’t think  
> string interpolation was necessary for that variable, and instead you  
> just wrote the variable next to the string?

This was what did it!  
Thank you Sir!

file=“dev.log”  
FileUtils.cp("#{file}", “#{file}.copied”)  
ZIPDIR = “/usr/local/”  
FileUtils.mv("#{file}.copied","#{ZIPDIR}#{file}.ts

---

<div class="post-metadata">

**Author:** ![bloodniece](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bloodniece](https://www.ruby-forum.com/u/bloodniece)\
**Post date:** [August 14, 2009, 6:06am UTC](https://www.ruby-forum.com/t/move-a-file/173672/5 "2009-08-14T06:06:20Z")

</div>

Hi,

Am Freitag, 14. Aug 2009, 08:46:49 +0900 schrieb Derek S.:

> > >
> 
> Thank you Sir!
> 
> FileUtils.mv("#{file}.copied","#{ZIPDIR}#{file}.ts

I think another slash won’t hurt in case you occur to forget it.

FileUtils.mv("#{file}.copied","#{ZIPDIR}/#{file}.tst"  
^^^

Bertram
