Module: Raz::FileOperations

Defined in:
lib/raz/file_operations.rb

Defined Under Namespace

Classes: NotExistingFile, UnknownFileType

Class Method Summary collapse

Class Method Details

.copy_item(src, dest) ⇒ Object

Method to copy file and keep same informations (owner, mtime, …) as original file

Parameters:

  • src (String)
  • dest (String)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/raz/file_operations.rb', line 12

def copy_item(src, dest)
  if !File.exist?(src)
    raise NotExistingFile, "Unknown file type for source #{src}"
  elsif File.directory?(src)
    FileUtils.cp_r(src, dest, preserve: true)
  elsif File.file?(src)
    FileUtils.cp(src, dest, preserve: true)
  else
    raise UnknownFileType, "Unknown file type for source #{src}"
  end
end

.dir_entries(path) ⇒ Array<String>

Parameters:

  • path (String)

    path to folder

Returns:

  • (Array<String>)


30
31
32
33
34
35
# File 'lib/raz/file_operations.rb', line 30

def dir_entries(path)
  entries = Dir.entries(path)
  entries.delete('.')
  entries.delete('..')
  entries
end