How to copy a file to a non existing directory ?

  • Thread starter Martin Martinos
  • Start date
M

Martin Martinos

Is there a way to copy a file to a directory that does not exist ? If I
try

require 'fileutils'

FileUtils.cp('c:/trash.txt', 'c:/mart/martin.txt')

I get the following message :

c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': No such file or
director
y - c:/mart/martin.txt (Errno::ENOENT)
from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `open'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `copy_file'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `open'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `copy_file'
from c:/ruby/lib/ruby/1.8/fileutils.rb:459:in `copy_file'
from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in `cp'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in
`fu_each_src_dest'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in
`fu_each_src_dest0'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in
`fu_each_src_dest'
from c:/ruby/lib/ruby/1.8/fileutils.rb:382:in `cp'
from C:/Documents and Settings/mchabot/Desktop/CompileServer/New
Ruby Pr
ogram.rb:3
 
R

Robert Conn

Hi

You'll need to create the directory first with

FileUtils.mkdir('c:/mart')

Bob
 
M

Michael Fellinger

Is there a way to copy a file to a directory that does not exist ? If I
try

require 'fileutils'

FileUtils.mkdir_p(File.dirname('c:/mart/martin.txt'))

FileUtils.cp('c:/trash.txt', 'c:/mart/martin.txt')

I get the following message :

c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': No such file or
director
y - c:/mart/martin.txt (Errno::ENOENT)
from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `open'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `copy_file'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `open'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `copy_file'
from c:/ruby/lib/ruby/1.8/fileutils.rb:459:in `copy_file'
from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in `cp'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in
`fu_each_src_dest'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in
`fu_each_src_dest0'
from c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in
`fu_each_src_dest'
from c:/ruby/lib/ruby/1.8/fileutils.rb:382:in `cp'
from C:/Documents and Settings/mchabot/Desktop/CompileServer/New
Ruby Pr
ogram.rb:3
 

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

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top