簡體   English   中英

在Ruby中更改文件的權限

[英]Change permissions of file in Ruby

我的代碼如下

 def initialise
   @doc_path =nil
   @user= nil
end
def execute
   oscmd = Common::OsCmd.new
   oscmd.log = @log.info("message")
   File.open("#{@doc_path}/new.doc","w") do |f|
      f.puts "/#{@name}  /people/* "
      File.chmod(0777,"#{@doc_path}/new.doc")
      FileUtils.chown("#{@user}, #{@user}, #{@doc_path}")
   end
end

所以我的代碼通過其他配置文件中的標記化來執行,其中它具有doc_pathuser

我的代碼在chownchmod上給出了錯誤

通過在chown中傳遞有效用戶來嘗試以下操作:

def self.execute
   oscmd = Common::OsCmd.new
   oscmd.log = @log.info("message")
   File.open("#{@doc_path}/new.doc","w") do |f|
      f.puts "/#{@name}  /people/* "
      File.chmod(0777,"#{@doc_path}/new.doc")
      FileUtils.chown 'vinod', 'vinod', "#{@doc_path}" 
   end #-- do ends here
end #-- def ends here

chown用法:

http://apidock.com/ruby/FileUtils/chown

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM