Forum: Ruby FileUtils in widows

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B35e9113d2d517beb19ebd9eeb4d77be?d=identicon&s=25 Jon Dale (jjd)
on 2007-07-29 00:03
I am fairly new to ruby and am working with windows xp.  I'm trying to
copy files from one directory to another using the FileUtils module.
When I run the program, I get a Permission Denied error (EACCES).  Any
thoughts on how to get this to work?

files.each do |f|
  next if f == "." or f == ".."
  FileUtils.copy(dir,newdir)
end

Thanks in advance for any help.

jjd
2ee1a7960cc761a6e92efb5000c0f2c9?d=identicon&s=25 William James (Guest)
on 2007-07-29 00:16
(Received via mailing list)
On Jul 28, 5:03 pm, Jonathan Dale <jdal...@yahoo.com> wrote:
> I am fairly new to ruby and am working with windows xp.  I'm trying to
> copy files from one directory to another using the FileUtils module.
> When I run the program, I get a Permission Denied error (EACCES).  Any
> thoughts on how to get this to work?
>
> files.each do |f|
>   next if f == "." or f == ".."
>   FileUtils.copy(dir,newdir)

You forgot to use f in this line.
B35e9113d2d517beb19ebd9eeb4d77be?d=identicon&s=25 Jon Dale (jjd)
on 2007-07-29 00:23
>> files.each do |f|
>>   next if f == "." or f == ".."
>>   FileUtils.copy(dir,newdir)
>
> You forgot to use f in this line.

Isn't the f covered in the do statement?  I'm not sure how else f would
be implemented.
Bfcc9047bea80035a936648dc1912ec4?d=identicon&s=25 Gavin Sinclair (Guest)
on 2007-07-29 02:01
(Received via mailing list)
On Jul 29, 8:24 am, Jon Dale <jdal...@yahoo.com> wrote:
> >> files.each do |f|
> >>   next if f == "." or f == ".."
> >>   FileUtils.copy(dir,newdir)
>
> > You forgot to use f in this line.
>
> Isn't the f covered in the do statement?  I'm not sure how else f would
> be implemented.

FileUtils.copy(f, newdir)
B35e9113d2d517beb19ebd9eeb4d77be?d=identicon&s=25 Jon Dale (jjd)
on 2007-07-29 02:44
Gavin Sinclair wrote:
> On Jul 29, 8:24 am, Jon Dale <jdal...@yahoo.com> wrote:
>> >> files.each do |f|
>> >>   next if f == "." or f == ".."
>> >>   FileUtils.copy(dir,newdir)
>>
>> > You forgot to use f in this line.
>>

>
> FileUtils.copy(f, newdir)

Thanks, works now.  I stared at it so long I couldn't see the obvious!
2ee1a7960cc761a6e92efb5000c0f2c9?d=identicon&s=25 William James (Guest)
on 2007-07-29 02:51
(Received via mailing list)
On Jul 28, 6:58 pm, Gavin Sinclair <gsincl...@gmail.com> wrote:
>
> FileUtils.copy(f, newdir)

Or
FileUtils.copy( "#{dir}/#{f}", newdir)

FileUtils.copy isn't a mind-reader.
It doesn't know (or assume) that you have put
the name of the file in variable named f.
It doesn't know that it is being invoked
inside of a loop.
This topic is locked and can not be replied to.