2013-08-27 2 views
2

/template 디렉토리 (보석 내부)의 파일을 콘솔의 현재 디렉토리에 복사하는 gem을 만들고 있습니다.Ruby - FileUtils copy_file Windows에서 권한이 거부되었습니다.

는 다음과 같이 표시됩니다

require "fileutils" 

# Get the console's current directory 
destination_dir = Dir.pwd 

# Home directory of my gem, looks like C:/Ruby193/lib/ruby/gems/1.9.1/gems/my_gem-1.0.0 
home_dir = File.expand_path("..", File.dirname(__FILE__)) 

# Template directory, looks like C:/Ruby193/lib/ruby/gems/1.9.1/gems/my_gem-1.0.0/template 
template_dir = File.join(home_dir, "template") 

FileUtils.copy_file(template_dir, destination_dir) 

그리고이 오류가있어 : 나는 디렉토리가하는 것을 확인 Dir[template_dir]을 실행하여 존재하는 한

C:/Ruby193/lib/ruby/1.9.1/fileutils.rb:1370:in `initialize': Permission denied - 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/my_gem-1.0.0/template (Errno:: 
EACCES) 

합니다.

모든 솔루션? 감사합니다

UPDATE 내가 copy_file 전에이 줄을 추가 @Babai

아래의 의견에 대답,하지만 여전히 작동하지 않습니다. 내가 제대로하고 있니?

FileUtils.chmod(0777, template_dir) 

@mudasobwa는

여기에 코드

# puts "#{template_dir} \n #{destination_dir}" 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/my_gem-1.0.0/template 
C:/Users/myname/Documents/Test 
+0

cp_r를 사용할 필요가 - http://www.ruby-doc.org/stdlib-2.0/libdoc/fileutils/rdoc/FileUtils.html#method-c- 먼저 chmod? –

+0

'FileStyle.copy_file' 전에'puts "# {template_dir} ⇒ # {destination_dir}"과 같은 디버깅 결과를 출력하고 보여줄 것입니까? – mudasobwa

+0

답장을 보내 주셔서 감사합니다. 나는 당신에게 대답하기 위해 질문에 대한 업데이트를 추가했습니다. – hrsetyono

답변

2

내 나쁜 결과입니다. 내 template 디렉토리에 다른 폴더가 있습니다. 그래서 나는 당신이 시도 할 수 대신 copy_file

FileUtils.cp_r(template_dir, destination_dir) 
관련 문제