move a file

D

Derek Smith

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")
 
B

Bertram Scharpf

Hi,

Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek Smith:
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
 
7

7stud --

Bertram said:
Hi,

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

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?
 
D

Derek Smith

7stud said:
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
 
B

Bertram Scharpf

Hi,

Am Freitag, 14. Aug 2009, 08:46:49 +0900 schrieb Derek Smith:
This was what did it!
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top