Module: OnlyofficeFileHelper::DirectoryMethods
- Included in:
- FileHelper
- Defined in:
- lib/onlyoffice_file_helper/directory_methods.rb
Overview
Methods used to work with directories
Instance Method Summary collapse
- #delete_directory(path) ⇒ Object
- #directory_hash(path) ⇒ Object
- #list_file_in_directory(directory, extension = nil) ⇒ Object
Instance Method Details
#delete_directory(path) ⇒ Object
6 7 8 |
# File 'lib/onlyoffice_file_helper/directory_methods.rb', line 6 def delete_directory(path) FileUtils.rm_rf(path) if Dir.exist?(path) end |
#directory_hash(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/onlyoffice_file_helper/directory_methods.rb', line 10 def directory_hash(path) files = [] Dir.foreach(path).sort.each do |entry| next if %w[.. .].include?(entry) full_path = File.join(path, entry) files = root_dir_hash(files, full_path) end files.keep_if { |current| current.end_with?('_spec.rb') } files end |
#list_file_in_directory(directory, extension = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/onlyoffice_file_helper/directory_methods.rb', line 22 def list_file_in_directory(directory, extension = nil) paths = [] Find.find(directory) do |path| next if FileTest.directory?(path) paths << path if extension.nil? || File.extname(path) == ".#{extension}" end paths rescue Errno::ENOENT [] end |