[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to force a copy over a read-only file

Martin Martinos

1/15/2008 12:46:00 AM

I want to copy a folder over an existing one. Some files are read-only.
When I do it I get the following error:

C:/Ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': Permission
denied - Folder2/./coco.txt (Errno::EACCES)

The Folder2/./coco.txt file is read-only

Here is the code:

require 'fileutils'
include FileUtils::Verbose

cp_r('Folder1/.','Folder2')


Does anybody has an idea how I can fix this ? I tried the :force option
and it looks like it's not supported.

Note: I am on a Windows platform.

Thanks in advance
--
Posted via http://www.ruby-....

2 Answers

Glen Holcomb

1/15/2008 9:40:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Jan 14, 2008 5:45 PM, Martin Martinos <mchabotsol@hotmail.com> wrote:

> I want to copy a folder over an existing one. Some files are read-only.
> When I do it I get the following error:
>
> C:/Ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': Permission
> denied - Folder2/./coco.txt (Errno::EACCES)
>
> The Folder2/./coco.txt file is read-only
>
> Here is the code:
>
> require 'fileutils'
> include FileUtils::Verbose
>
> cp_r('Folder1/.','Folder2')
>
>
> Does anybody has an idea how I can fix this ? I tried the :force option
> and it looks like it's not supported.
>
> Note: I am on a Windows platform.
>
> Thanks in advance
> --
> Posted via http://www.ruby-....
>
>
You need to change the permissions, either via the operating system
(independently from your script) or do it in your script before you copy.

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

Martin Martinos

1/17/2008 2:51:00 PM

0

Glen Holcomb wrote:
> On Jan 14, 2008 5:45 PM, Martin Martinos <mchabotsol@hotmail.com> wrote:
>
>> require 'fileutils'
>> Thanks in advance
>> --
>> Posted via http://www.ruby-....
>>
>>
> You need to change the permissions, either via the operating system
> (independently from your script) or do it in your script before you
> copy.
>
> --
I thought about this solution, but in fact I don't want to change the
state of the other files that are in the destination location.
If I want to do that I need to do something like:


require 'pathname'
require 'fileutils'

include FileUtils::Verbose

def cp_rf(src, dest)
src_files = Dir[File.join(src, '**/*.*')]
src_files.each do |src_file|
rel_path_src =
Pathname.new(src_file).relative_path_from(Pathname.new(src))
dest_file = dest + rel_path_src
dest_dirname = File.dirname(dest_file)
mkdir(dest_dirname) unless File.exist?(dest_dirname)
if ( File.exist?(dest_file.to_s) &&
!File.writable?(dest_file.to_s))
File.chmod(0664, dest_file)
end
cp(src_file, dest_file)
end
end

I there a more easier way to do that. Because It is much more easier to
write:
system("xcopy c:\temp c:\temp2 /e /r /Y")

I feel that the FileUtils module is not complete.



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