Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to copy a file to a non existing directory ?

Reply
Thread Tools

How to copy a file to a non existing directory ?

 
 
Martin Martinos
Guest
Posts: n/a
 
      11-07-2006
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Conn
Guest
Posts: n/a
 
      11-07-2006
Hi

You'll need to create the directory first with

FileUtils.mkdir('c:/mart')

Bob


On 7 Nov 2006, at 22:05, Martin Martinos wrote:

> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>



 
Reply With Quote
 
 
 
 
Michael Fellinger
Guest
Posts: n/a
 
      11-07-2006
On 11/8/06, Martin Martinos <(E-Mail Removed)> wrote:
> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


 
Reply With Quote
 
Martin Martinos
Guest
Posts: n/a
 
      11-07-2006
Michael Fellinger wrote:
> On 11/8/06, Martin Martinos <(E-Mail Removed)> wrote:
>> 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')


Thanks for your helps it works fine.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Existing Dll - using Functions from an existing dll Tristin.Colby@gmail.com Ruby 0 02-05-2008 07:38 PM
Why no existing Java type to existing XML schema binding support? nrm Java 3 04-10-2006 04:52 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
Passing non existing IIS directory to ASP parameter nungon ASP General 9 07-18-2005 09:11 AM



Advertisments