このエントリーをはてなブックマークに追加


ファイルのパーミッション変更方法

FileUtils.chmodを利用するとファイルのパーミッションを変更することができます。
require "fileutils"が必要になります。


スポンサーリンク

パーミッション変更のサンプルソース

require "fileutils"

f = File.open("hello.sh", "w")
f.puts("#!/bin/bash")
f.puts("echo Hello world!")
f.close
FileUtils.chmod(0755, "hello.sh")

実行結果

$ ruby file_chmod.rb 
$ ls -l hello.sh 
-rwxr-xr-x  1 sakura  staff  30  2 11 21:42 hello.sh
$ ./hello.sh 
Hello world!

スポンサーリンク


添付ファイル: filefile_chmod.rb 492件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-03-20 (金) 22:31:23