Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/file.rb

Constant Summary collapse

FILE_ATTRIBUTE_READONLY =
"0x1".hex

Class Method Summary collapse

Class Method Details

.read_only?(path) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File 'lib/file.rb', line 5

def self.read_only?(path)
  raise "'#{path}' does not exist" unless(File.exists?(path))
	kernel32 = Fiddle::Handle.new("kernel32")
	get_file_attributes = Fiddle::Function.new(kernel32['GetFileAttributesA'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_LONG)

	return ((get_file_attributes.call(path) & FILE_ATTRIBUTE_READONLY) == 1) ? true : false;
end